Firebase is a product of Google which helps developers to build, manage, and grow their apps easily. It helps developers to build their apps faster and in a more secure way. No programming is required on the firebase side which makes it easy to use its features more efficiently. It provides cloud storage and uses NoSQL for the storage of data.
Django, on the other hand, is a Python-based web framework which allows you to quickly create web application without all the installation or dependency problems that you normally will find with other frameworks.
Here we will learn how can we implement a simple Django app that can retrieve PDF files stored in firebase. In this article, we will primarily focus on the Django aspect of it. If you wish to follow along, upload a dummy PDF in your firebase storage. If you are new to firebase then please refer to this.
Here, We are going to learn How we can retrieve PDF using Django in Firebase.
Creating a project in Django:
Use the below command to create a Django project:
$ django-admin startproject pdffinder
Let’s verify your Django project works. Change into the outer project directory, if you haven’t already, and run the following commands:
$ python manage.py runserver
You’ll see the following output on the command line:
Performing system checks... System check identified no issues (0 silenced). You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them. April 14, 2021 - 15:50:53 Django version 3.2, using settings 'pdffinder.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
Integrating Firebase Database to Django Project:
Now, we hope that you have already created a project in Django. If not then refer to How to Create a Basic Project using MVT in Django? Since we are using firebase as a Database, we need to install pyrebase . For this type the following command in terminal:
$pip install pyrebase4
Follow the below steps to retrieve PDF file in Django from firebase:
Step 1: Move into the pdffinder project directory.
Step 2: Go to urls.py file and create a path to move to the webpage to search for data.
Step 3: Then move to views.py file and write the following function to render to the HTML page.
Step 4: Then we will move to search.html page and write the following code to search for data in firebase. Comments are written inside to understand it better.
Step 5: Go to urls.py file and create a path to move to searchnotes function in views.py to search for data.
Step 6: Then move to views.py file and write the following function to search for the PDF with the given name.
Step 7: Then we will move to searchnotes.html page and will show the PDF as we got the link of PDF from firebase.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course