Skip to content
Related Articles

Related Articles

Improve Article

How to create a new project in Django using Firebase Database?

  • Difficulty Level : Medium
  • Last Updated : 30 Jun, 2021

Django is a Python-based web framework that allows you to quickly create efficient web applications. If you are new to Django then you can refer to Django Introduction and Installation. Here we are going to learn How to create a Django project using Firebase as Database . 

How to create a new project in Firebase ?

Step 1: Firstly, We are going to Create a project on Firebase to connect our static web page. Visit Firebase Page For Configuring Your Project –

Click On Add Project Button.

Step 2: Give a Name To your Project and Click On Continue Button.

 Step 3: Now Click On Continue Button.

Step 4: Now Choose Default Account For Firebase and Click On Create Project.

Step 5: Now Your Project is created. You are Good to Go. Click on Continue .

Step 6:  Now Click On 3rd icon that’s Web Button(</>).

Step 7: Give a nickname  to your Web Project and Click On Register App

Step 8: Now you will see the configuration of your App like this. Copy this Code somewhere .You wlll need it later.

Step 9 : Click On The Realtime Database button As Shown In Figure. 

Step 10: Now Click On Create Database.

Step 11: Now Click On Test Mode and then Click On Enable.

Now, We will Add Some Data and will try to Retrieve that using our Website

Integrating Firebase Database to Django Project – 

Now, I hope that you have already create 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 Database , We need to install pyrebase . For this Type the following Command in terminal

$pip install pyrebase4

Create a file in your project directly. The Structure should be like this . file


from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
    path('', views.home),


from django.shortcuts import render
import pyrebase
    apiKey: "Use Your Api Key Here",
    authDomain: "Use Your authDomain Here",
    databaseURL: "Use Your databaseURL Here",
    projectId: "Use Your projectId Here",
    storageBucket: "Use Your storageBucket Here",
    messagingSenderId: "Use Your messagingSenderId Here",
    appId: "Use Your appId Here"
authe = firebase.auth()
def home(request):
    day = database.child('Data').child('Day').get().val()
    id = database.child('Data').child('Id').get().val()
    projectname = database.child('Data').child('Projectname').get().val()
    return render(request,"Home.html",{"day":day,"id":id,"projectname":projectname })






<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Sample Project</title>
Project Name is {{ projectname }}
Project Id is {{ id }}
Day {{ day }}



Now move to your project directory and run our project using the given command :


python runserver


Project Output will be as Follow – 



 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

My Personal Notes arrow_drop_up
Recommended Articles
Page :