Looking for an easy way to add a database to your Python Web App? We’ll show you how to get started with Firebase integration in Python Django. Creating an app isn’t easy, but learning how to store your app’s vital data is! Here is a step-by-step tutorial to help you figure out how to connect to a Python Django Web App with Firebase and take the headache out of user authentication, data storage and retrieval. A Python app without Firebase is like a chicken without a hen-house; if you don’t have a place to store your eggs, it’s time to re-think the farm.
Check out this video, code below follows the video to help:
If you like videos like this consider donating $1, or simply turn off AdBlocker. Either helps me to continue making tutorials.
1. Configure FIREBASE
2. Installing Required Libraries
Installing pip
pip3 --version
sudo apt-get -y install python3-pip && sudo apt-get update
Installing Pyrebase
Installing Django
sudo pip3 install django
3. Working with Django
Creating new Django Project :
# sudo django-admin startproject cpanel # cd cpanel # python3 manage.py runserver //Open browser & type : 127.0.0.1:8000 //Output : IT'S WORKED //now make migrations: # python3 manage.py migrate // create a directory named templates # mkdir templates // go to cpanel directory and create views.py file # cd cpanel # touch views.py // go to settings.py file and configure the templates directory over there // go to line 57 and edit it: 'DIRS': ['templates'],
Code for Views.py :
import pyrebase from django.shortcuts import render | |
config = { | |
‘apiKey‘: “AIzaS–your config here —fOMd4pYUkbkZVvI“, | |
‘authDomain‘: “cpanel-5e873.firebaseapp.com“, | |
‘databaseURL‘: “https://cpanel-5e873.firebaseio.com“, | |
‘projectId‘: “cpanel-5e873“, | |
‘storageBucket‘: “cpanel-5e873.appspot.com“, | |
‘messagingSenderId‘: “579985583952“ | |
} | |
firebase = pyrebase.initialize_app(config) | |
auth = firebase.auth() | |
def singIn(request): | |
return render(request, “signIn.html“) | |
def postsign(request): | |
email=request.POST.get(‘email‘) | |
passw = request.POST.get(“pass“) | |
try: | |
user = auth.sign_in_with_email_and_password(email,passw) | |
except: | |
message = “invalid cerediantials“ | |
return render(request,“signIn.html“,{“msg“:message}) | |
print(user) | |
return render(request, “welcome.html“,{“e“:email}) |
Code for Urls.py :
from django.contrib import admin | |
from django.conf.urls import url | |
from . import views | |
urlpatterns = [ | |
url(r‘^admin/‘, admin.site.urls), | |
url(r‘^$‘,views.singIn), | |
url(r‘^postsign/‘,views.postsign), | |
] |
Code for Html Templates :
Welcome.html
That’s end up with great on Tutorial on Python Django with Firebase : Getting Started and Firebase Authentication, I hope you guys enjoyed it 🙂
Get full source code for Django Project Here.
django-admin.py startproject starts pycharm or visual studio IDE rather than creating project. Help me please
what about hosting django projects on firebase?
Because the firebase cli redirects everything to the public folder which firebase serves..
I was looking for some tutorial about it and found nothing !!
How to save a user on the db?
FIrebase DB
sorry to say, but you can't host django on firebase hosting. For that you can use google cloud console check out this blog : https://hackanons.com/2018/10/python-django-webser-hosting-on-google.html
oh my very useful and easy article , thanks a ton
Make money on kasino online and do not regret anything gamble casino with us Make money on kaino online and do not regret anything.
good concept
Thanks for documenting Django-Pyrebase-firebase
i got an error it says
https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=AIzaS–your%20config%20here%20—fOMd4pYUkbkZVvI%5D {
"error": {
"code": 400,
"message": "API key not valid. Please pass a valid API key.",
"errors": [
{
"message": "API key not valid. Please pass a valid API key.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
please help
Hi DEAR thanks for this great article i really like this post and i love your blog you;—————> Latest Free Download Good Morning Images, Beautiful Good Morning Pictures, Good Morning <—————
—Love Couple Romantic Good morning images Free Downlaod For Husband wishes–
<:>
-Good Morning Nature Photos Full Hd Free Download 2019
<:
Beautiful Happy Birthday Wishes Pictures, Photos, Images, and Pics Free Download With Name
Bes 5G Mobile Phone List upcoming smartphones 2019
How To Get FREE Mobile Balance of Rs. 500 With Bank Alfalah App
.
Apple iPhone11 Pro Max specification and price Full Details
>
Apple iPhone 11 specification and price Full Details
,.
Apple iPhone11 pro specification and price Full Details
earn free 1000$ without any investment Earn free 100$
Great article, thanks.
def postsign(request):
email = request.POST.get('email')
passw = request.POST.get("pass")
message = "Login succesfull"
Se debe definir message antes de el except
Al-Zahra area, which is one of the largest regions in the State of Kuwait, and we at Kuwait فني تكييف company are happy to offer repair services for Al-Zahraa Air Conditioning to all of our customers in this region
فني تكييف الكويت تقدم لكم جميع خدمات فني تكييف ٢٤ ساعه و تصليح مكيفات و فني تكييف مركزي هندي
، صيانة تكييف مركزي و تصليح تكييف مركزي و تصليح وحدات تكييف
تركيب تكييف و كمبروسرات جديد و مستامل جميع مناطق بالكويت فني تكييف