Header Ads

Python Django with Google Firebase Tutorial: Firebase Database Retrieve Data to template #Part5


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}} &nbsp;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 :)
Get full source code for Django Project Here.

45 comments:

  1. I think that thanks for the valuabe information and insights you have so provided here. retrieve data from USB flash drive

    ReplyDelete
  2. The method requires the combination of efforts of both the administrator and the developer for the database. Database Diagram Tool

    ReplyDelete
  3. 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

    ReplyDelete
  4. I think that thanks for the valuabe information and insights you have so provided here. odzyskiwanie danych z uszkodzonego telefonu

    ReplyDelete
  5. Your website is really cool and this is a great inspiring article. Thank you so much. tattoo artists application

    ReplyDelete
  6. very interesting post.this is my first time visit here.i found so mmany interesting stuff in your blog especially its discussion..thanks for the post! Great Google Reviews

    ReplyDelete
  7. 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.

    ReplyDelete
  8. 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

    ReplyDelete
  9. 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

    ReplyDelete
  10. 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

    ReplyDelete
  11. The Data Protection Act 1998 ("DPA"), sets down eight data assurance rules that any association handling data of people must follow.
    pengeluaran hk

    ReplyDelete
  12. Pasarqq tempat Bermain judi bandarq online tentunya menjadi di antara pilihan yang tidak sedikit dipilih oleh pemain website bandarq .Bisa anda lihat profile terkait pasarqq ternama melalui metode klik link https://findery.com/pasarqq , lalu https://www.thebaynet.com/profile/noverakasanti888 kemudian https://fontlibrary.org/en/member/pasarqq/ dan juga http://www.myfolio.com/pasarqq.
    Selain itu juga pasarqq ini memiliki homepage personal seperti https://pasarqq.cabanova.com/
    http://rebuildingtogethernb.org/selamat-datang-di-situs-poker-online-pasarqq/
    http://sonidoslibertarios.org/selamat-datang-di-situs-poker-online-pasarqq/
    http://jonnymugwump.com/selamat-datang-di-situs-poker-online-pasarqq/

    ReplyDelete
  13. hadir dengan fitur lengkap mengenai Data hk menjadi sesuatu yang sangat anda butuhkan serta kingdomtoto memberikan pelayanan togel online terbaik dengan pengeluaran hk

    ReplyDelete
  14. Halo pemburu data togel seperti data sydney bisa dilakukan melalui halaman ini dan juga data sgp beserta pengeluaran sydney.

    ReplyDelete
  15. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. Buy Pinterest Followers

    ReplyDelete
  16. Video applications such as QiK and Ustream are handy tools for documenting important events. But while many people simply use their SmartPhone to record video of everyday things such as baby showers and graduation, there are other, better uses for these applications. 無料

    ReplyDelete
  17. This is my first time visit to your blog and I am very interested in the articles that you serve. Provide enough knowledge for me. Thank you for sharing useful and don't forget, keep sharing useful info: Buy Google Reviews

    ReplyDelete
  18. 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

    ReplyDelete
  19. Amazing Post, Thank you for sharing this post really this is awesome and very useful.
    1337xunblock

    ReplyDelete
  20. 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

    ReplyDelete
  21. You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers. Admond Lee

    ReplyDelete
  22. 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

    ReplyDelete
  23. Take for instance a business that is hoping to commission another site to be planned and created and need to guarantee that the new site will rank high in the web indexes.blog comment service

    ReplyDelete
  24. 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

    ReplyDelete
  25. You have done a amazing job with you website goldcoders hyip templates

    ReplyDelete
  26. Past email, online networking advertising and internet searcher showcasing, you can wander into a large group of other advanced promoting endeavors. blog comments service in 1$

    ReplyDelete
  27. You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers. what is analytics

    ReplyDelete
  28. I use Python.. It's just ROCK!

    ReplyDelete
  29. will computerized promoting advantage your business" and answer the inquiry .Business Card Design

    ReplyDelete
  30. Grants - There are a large number of associations that present honors across different classes to computerized offices conveying Stationary Design

    ReplyDelete
  31. This is also a very good post which I really enjoyed reading. It is not every day that I have the possibility to see something like this.. hyip template

    ReplyDelete
  32. This is also a very good post which I really enjoyed reading. It is not every day that I have the possibility to see something like this.. hyip template

    ReplyDelete
  33. 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

    ReplyDelete
  34. coordinates the exercises that are important for a business thought to turn into an organization Cooperate Identity design

    ReplyDelete
  35. 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

    ReplyDelete
  36. 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

    ReplyDelete
  37. 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

    ReplyDelete
  38. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. antminer s17 pro setup

    ReplyDelete
  39. Thank you for your post, I look for such article along time, today i find it finally. this post give me lots of advise it is very useful for me. hyip template

    ReplyDelete
  40. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites! hyip template

    ReplyDelete
  41. I see the greatest contents on your blog and I extremely love reading them. goldcoders hyip templates

    ReplyDelete
  42. Consider this. What are the suggestions? On the off chance that YouTube is possibly going to turn into the #1 web crawler on the planet, what are the suggestions for your online business? What's more, okay need to be in the ideal spot at the perfect time with YouTube? I certainly think so. https://y.tools/contact-us/

    ReplyDelete

Powered by Blogger.