Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
How to implement FirebaseDB with a Django Web Application

Am trying to implement Firebase Realtime Database with my Django Web Application. After properly setting up the configuration with Firebase, I got confused about how data will write into my Firebase Database from my Django website instead of using Sqlite, or Postgres.

Under settings.py, do I need to set my engine to Firebase? Am totally confused here. I do not want to use the normal ORM such as Sqlite, Postgres etc. I want my app to use Firebase.

Is there something else I need to understand about Firebase?

settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

pyrebase_settings file

import pyrebase

config = {
    "apiKey": "my_api_key_is_here",
    "authDomain": "my_auth_domain_is_here",
    "databaseURL": "my_firebase_database_url_is_here",
    "projectId": "my_firebase_project_id_is_here",
    "storageBucket": "my_firebase_storageBucket_is_here",
    "serviceAccount": "my_serviceAccount.json_file_path_is_here",
    "messagingSenderId": "messagingSenderId_is_here"
}

# initialize app with config
firebase = pyrebase.initialize_app(config)

# authenticate a user
auth = firebase.auth()
user = auth.sign_in_with_email_and_password("email@usedforauthentication.com", "FstrongPasswordHere")


db = firebase.database()
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

take a look at the database section of the doc. It details how you would interact with the database API. Typically you would use these in your views where you need to save or retrieve something from the database.

e.g say you want a view that gets users, you could have something like this:

#views.py
from pyrebase_settings import db, auth
from django.shortcuts import render

def get_users(request):
    users = db.child("users").get()
    return render(request, 'users.html', {'users': users.val()})

The documentation for retrieving data can be seen here

also say you want a view to save(signup) users, you could have something like so:

#views.py
from pyrebase_settings import db, auth

def signup(request):
   form = SignupForm(request.POST)
   if form.is_valid():
       email = form.cleaned_data('email')
       password = form.cleaned_data('password')
       auth.create_user_with_email_and_password(email, password)
   # the rest of your code goes here

the create_user_with_email_and_password method is documented here

PS. I have never made use of the pyrebase library so I write only based on what is specified in its docs. Also I am only writing these django snippets off the top of my head so forgive me if there are any syntax errors or typos :)

Hope this helps :)

over 4 years ago · Santiago Trujillo Relatório

0

Is there something else I need to understand about Firebase?

No, there is something you need to understand about Django -- it is designed to use a relational database engine as its primary data store. Firebase is not relational.

Sorry to be the bearer of bad news.

Many answers on this question are missing this point, and suggesting code or libraries that let you access Firebase from Python. Sure, that's possible. But that doesn't make it work as a primary data store for Django. Django's ORM features and contrib apps all presume a relational database.

In order for this to work you'd need something along the lines of django-nonrel that supported Firebase. As far as I know that doesn't exist.

over 4 years ago · Santiago Trujillo Relatório

0

consider having a look at the fcm-django library here https://github.com/xtrinch/fcm-django

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda