In previous tutorial we covered Pushing data to Firebase Database using Python Django & Pyrebase library. So, here next part comes i.e. Fetching/Retrieving data from Firebase database to Django Template.
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.
Transcript / Cheat Sheet :
Templates :
Welcome.html :
First we need to edit our welcome.html, need to add Onclick function for redirecting check report button to check.html template
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<style> | |
div{ | |
position : absolute; | |
right : 10px; | |
top : 5px | |
} | |
</style> | |
</head> | |
<body> | |
<div> | |
<button type="button" onclick="location.href='{% url 'log' %}'">Logout</button> | |
</div> | |
Welcome {{e}} | |
<br><br> | |
<button type="button" onclick="location.href='{% url 'create' %}'">Create Report</button> | |
<button type="button" onclick="location.href='{% url 'check' %}'">Check Report</button> | |
</body> | |
</html> |
Check.html
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<style> | |
div{ | |
position : absolute; | |
right : 10px; | |
top : 5px | |
} | |
</style> | |
</head> | |
<body> | |
<div> | |
<button type="button" onclick="location.href='{% url 'log' %}'">Logout</button> | |
</div> | |
Welcome {{e}} | |
<br><br> | |
{% for time,dat,work in comb_lis %} | |
Date: {{dat}} Work: <a href="/post_check/?z={{time}}" >{{work}}</a> | |
<br> | |
{% endfor %} | |
</body> | |
</html> |
Post_Check.html
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<style> | |
div{ | |
position : absolute; | |
right : 10px; | |
top : 5px | |
} | |
</style> | |
</head> | |
<body> | |
<div> | |
<button type="button" onclick="location.href='{% url 'log' %}'">Logout</button> | |
</div> | |
Welcome {{e}} | |
<br><br> | |
Date: {{d}}<br> | |
Work : {{w}}<br> | |
Progress: {{p}}<br> | |
</body> | |
</html> |
Views.py :
import pyrebase from django.shortcuts import render | |
from django.contrib import auth | |
config = { | |
'apiKey': "AIzaSyB0Il0NLQPxxDyMgoE0fOMd4pYUkbkZVvI", | |
'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) | |
authe = firebase.auth() | |
database=firebase.database() | |
def signIn(request): | |
return render(request, "signIn.html") | |
def postsign(request): | |
email=request.POST.get('email') | |
passw = request.POST.get("pass") | |
try: | |
user = authe.sign_in_with_email_and_password(email,passw) | |
except: | |
message="invalid credentials" | |
return render(request,"signIn.html",{"messg":message}) | |
print(user['idToken']) | |
session_id=user['idToken'] | |
request.session['uid']=str(session_id) | |
return render(request, "welcome.html",{"e":email}) | |
def logout(request): | |
auth.logout(request) | |
return render(request,'signIn.html') | |
def signUp(request): | |
return render(request,"signup.html") | |
def postsignup(request): | |
name=request.POST.get('name') | |
email=request.POST.get('email') | |
passw=request.POST.get('pass') | |
try: | |
user=authe.create_user_with_email_and_password(email,passw) | |
except: | |
message="Unable to create account try again" | |
return render(request,"signup.html",{"messg":message}) | |
uid = user['localId'] | |
data={"name":name,"status":"1"} | |
database.child("users").child(uid).child("details").set(data) | |
return render(request,"signIn.html") | |
def create(request): | |
return render(request,'create.html') | |
def post_create(request): | |
import time | |
from datetime import datetime, timezone | |
import pytz | |
tz= pytz.timezone('Asia/Kolkata') | |
time_now= datetime.now(timezone.utc).astimezone(tz) | |
millis = int(time.mktime(time_now.timetuple())) | |
print("mili"+str(millis)) | |
work = request.POST.get('work') | |
progress =request.POST.get('progress') | |
idtoken= request.session['uid'] | |
a = authe.get_account_info(idtoken) | |
a = a['users'] | |
a = a[0] | |
a = a['localId'] | |
print("info"+str(a)) | |
data = { | |
"work":work, | |
'progress':progress, | |
} | |
database.child('users').child(a).child('reports').child(millis).set(data) | |
name = database.child('users').child(a).child('details').child('name').get().val() | |
return render(request,'welcome.html', {'e':name}) | |
def check(request): | |
import datetime | |
idtoken = request.session['uid'] | |
a = authe.get_account_info(idtoken) | |
a = a['users'] | |
a = a[0] | |
a = a['localId'] | |
timestamps = database.child('users').child(a).child('reports').shallow().get().val() | |
lis_time=[] | |
for i in timestamps: | |
lis_time.append(i) | |
lis_time.sort(reverse=True) | |
print(lis_time) | |
work = [] | |
for i in lis_time: | |
wor=database.child('users').child(a).child('reports').child(i).child('work').get().val() | |
work.append(wor) | |
print(work) | |
date=[] | |
for i in lis_time: | |
i = float(i) | |
dat = datetime.datetime.fromtimestamp(i).strftime('%H:%M %d-%m-%Y') | |
date.append(dat) | |
print(date) | |
comb_lis = zip(lis_time,date,work) | |
name = database.child('users').child(a).child('details').child('name').get().val() | |
return render(request,'check.html',{'comb_lis':comb_lis,'e':name}) | |
def post_check(request): | |
import datetime | |
time = request.GET.get('z') | |
idtoken = request.session['uid'] | |
a = authe.get_account_info(idtoken) | |
a = a['users'] | |
a = a[0] | |
a = a['localId'] | |
work =database.child('users').child(a).child('reports').child(time).child('work').get().val() | |
progress =database.child('users').child(a).child('reports').child(time).child('progress').get().val() | |
i = float(time) | |
dat = datetime.datetime.fromtimestamp(i).strftime('%H:%M %d-%m-%Y') | |
name = database.child('users').child(a).child('details').child('name').get().val() | |
return render(request,'post_check.html',{'w':work,'p':progress,'d':dat,'e':name}) |
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.signIn), | |
url(r'^postsign/',views.postsign), | |
url(r'^logout/',views.logout,name="log"), | |
url(r'^signup/',views.signUp,name='signup'), | |
url(r'^postsignup/',views.postsignup,name='postsignup'), | |
url(r'^create/',views.create,name='create'), | |
url(r'^post_create/',views.post_create,name='post_create'), | |
url(r'^check/',views.check,name='check'), | |
url(r'^post_check/',views.post_check,name='post_check'), | |
] |
That’s end up with great on Tutorial on Python Django with Firebase: Firebase Database Retrieve Data to Django Template, I hope you guys enjoyed it 🙂
I think that thanks for the valuabe information and insights you have so provided here. retrieve data from USB flash drive
The method requires the combination of efforts of both the administrator and the developer for the database. Database Diagram Tool
These templates have the ability to make your online business run with efficiency and ease. They also ensure that your website approach remains systematic and organized.
nagy plüss maci
I think that thanks for the valuabe information and insights you have so provided here. odzyskiwanie danych z uszkodzonego telefonu
Your website is really cool and this is a great inspiring article. Thank you so much. tattoo artists application
SQLite database is really a customary circle document.dbdesigner.net This implies any procedure can without much of a stretch open it and overwrite it with garbage characters or roll out undesirable improvements.
All of a sudden, your drive will end up out of commission. Every so often, you will get a notice that something awful is going to occur. data recovery manchester uk
The default that appears to be most consistent when making your AdSense Ads is either a full standard over the top or base of your page or a 250 x 250 square advertisement that you put in the upper left of your page. All things considered, that is what every other person does, why not you?https://www.ppc-agency.london/post/tips-to-get-more-enquiries-from-ppc-campaigns
Information Science is basically an innovative and test process on the grounds that neither one of the we can find a last solution to the issue nor accurate strategy to arriving at one. ExcelR Data Science Courses
The Data Protection Act 1998 ("DPA"), sets down eight data assurance rules that any association handling data of people must follow.
pengeluaran hk
hadir dengan fitur lengkap mengenai Data hk menjadi sesuatu yang sangat anda butuhkan serta kingdomtoto memberikan pelayanan togel online terbaik dengan pengeluaran hk
Halo pemburu data togel seperti data sydney bisa dilakukan melalui halaman ini dan juga data sgp beserta pengeluaran sydney.
These arrangements can likewise be characterized as a subset of Big Data investigation arrangements utilized explicitly for vitality and utilities.Data Analytics Course in Bangalore
Amazing Post, Thank you for sharing this post really this is awesome and very useful.
1337xunblock
As website admins we were at the impulse of Googlebot, the apparently subjective algorithmic kingmaker that could represent the moment of truth a site medium-term through movements in web index situating. There was no real way to speak with Google about a site – either to comprehend what wasn't right with it, or to disclose to Google when something had been refreshed.
finance
Subsequently, while thinking about the plan and advancement of another site, a computerized organization is an a lot more intelligent decision since they truly have the full suite of aptitude and comprehend what they are discussing.
Digital Market service
Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well i really get amazed to read this. Its really good. goldcoders hyip templates
You have done a amazing job with you website goldcoders hyip templates
I use Python.. It's just ROCK!
will computerized promoting advantage your business" and answer the inquiry .Business Card Design
Grants – There are a large number of associations that present honors across different classes to computerized offices conveying Stationary Design
But, here's where it gets very powerful. Once it works on Google, simply duplicate it on as many PPC networks as you can get your hands on. This is by no means an easy strategy and like almost all the internet marketing programs out there its creator claims for it to be much easier than it actually is.negative keyword planner
coordinates the exercises that are important for a business thought to turn into an organization Cooperate Identity design
This customer is incredibly lucky to have built up a reliable after among past clients who generously talk about their inclinations, buys and post photographs of their prized exclusively improved vehicles on various well known, extraordinary intrigue car discussions on the Internet.Free Google Ads Audit
Poker online situs terbaik yang kini dapat dimainkan seperti Bandar Poker yang menyediakan beberapa situs lainnya seperti http://62.171.128.49/hondaqq/ , kemudian http://62.171.128.49/gesitqq/, http://62.171.128.49/gelangqq/, dan http://62.171.128.49/seniqq. yang paling akhir yaitu http://62.171.128.49/pokerwalet/. Jangan lupa mendaftar di panenqq
Just a Google AdWords confirmed proficient will have the option to help you and locate the missing connection. During assessment, many concealed issues will be found. Every thing will be examined and logged independently.
Google Ads Expert
peraktoto
peraktoto
peraktoto
peraktoto
peraktoto
peraktoto
peraktoto
peraktoto
peraktoto
peraktoto
peraktoto
peraktoto
peraktoto
peraktoto
I see the greatest contents on your blog and I extremely love reading them. goldcoders hyip templates
https://rajaperi.com/
kingdom4d
https://belutlistrik.com/
kingdomtoto
https://masterwla.com/
castletoto
https://gudangkosong.com/
98toto
Search engine optimization (SEO) is a mega-hot, high-paying field right now. Hence, job opportunities in SEO have grown significantly. This means the need for SEO training is growing by leaps and bounds. But, what type of SEO course is right for you, how much will it cost, is it online or off? Get answers to these questions, and more, here.PBN CHEAP RATES
From that point forward, you ought to have a blend of both positive and negative reviews left to react to. buy google places reviews
pasarqq
bisaqq
kingdomtoto
dewaqq
tarotqq
BANDAR PKV
crownqq
tiket kemenangan
I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article… Buy Bad Google Reviews
if you want to learn digital marketing in mumbai. excelr solutions providing best AI course in mumbai.for more details click here
digital marketing course
Two full thumbs up for this magneficent article of yours. I've really enjoyed reading this article today and I think this might be one of the best article that I've read yet. Please, keep this work going on in the same quality. mute the germs
This is a fantastic website and I can not recommend you guys enough. case mate
I have recently started a blog, the info you provide on this site has helped me greatly. Thanks for all of your time & work best online digital marketing courses
I really thank you for the valuable info on this great subject and look forward to more great posts digital marketing course online free
I think I have never seen such blogs ever before that has complete things with all details which I want. So kindly update this ever for us. HD lace
Going to graduate school was a positive decision for me. I enjoyed the coursework, the presentations, the fellow students, and the professors. And since my company reimbursed 100% of the tuition, the only cost that I had to pay on my own was for books and supplies. Otherwise, I received a free master’s degree. All that I had to invest was my time. Ridgedale Missouri
Thanks for the best blog. it was very useful for me.keep sharing such ideas in the future as well. wash hands
Thanks a lot for one’s intriguing write-up. It’s actually exceptional. Searching ahead for this sort of revisions. patriotic shirt
I think this is a standout amongst the most critical data for me. What"s more, i"m happy perusing your article. Be that as it may, ought to comment on some broad things buzz
Thanks for the informative and helpful post, obviously in your blog everything is good.. micro usb silver micro usbblac
wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries.
Data Science Course
wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries. keep it up.
data analytics course in Bangalore
For small projects in particular, a slide scanner can be a very good purchase. Dedicated scanners take either film strips or mounted slides. PYLE 22MP SLIDE FILM SCANNER