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.

81 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
  43. 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

    ReplyDelete
  44. From that point forward, you ought to have a blend of both positive and negative reviews left to react to. buy google places reviews

    ReplyDelete
  45. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me. anaconda install tensorflow

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

    Digital marketing course

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

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

    ReplyDelete
  49. This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
    data analytics courses

    ReplyDelete
  50. I truly like you're composing style, incredible data, thankyou for posting. website builder ecommerce

    ReplyDelete
  51. I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post. gadgetdeep pocket

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

    ReplyDelete
  53. This is a fantastic website and I can not recommend you guys enough. case mate

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

    ReplyDelete
  55. I really thank you for the valuable info on this great subject and look forward to more great posts digital marketing course online free

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

    ReplyDelete
  57. I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. chicago med season 5

    ReplyDelete
  58. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon. Branson West Missouri

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

    ReplyDelete
  60. Thanks for the best blog. it was very useful for me.keep sharing such ideas in the future as well. wash hands

    ReplyDelete
  61. It is perfect time to make some plans for the future and it is time to be happy. I've read this post and if I could I desire to suggest you some interesting things or suggestions. Perhaps you could write next articles referring to this article. I want to read more things about it! LED mini mirror

    ReplyDelete
  62. We are tied directly into the sate’s renewal database which allows us to process your request almost instantly. buy essays rechargeable LED

    ReplyDelete
  63. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. LED mini mirror

    ReplyDelete
  64. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. LED mini mirror

    ReplyDelete
  65. Thanks a lot for one’s intriguing write-up. It’s actually exceptional. Searching ahead for this sort of revisions. patriotic shirt

    ReplyDelete
  66. This is just the information I am finding everywhere. Thanks for your blog, I just subscribe your blog. This is a nice blog.. trump hat

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

    ReplyDelete
  68. Thanks for the informative and helpful post, obviously in your blog everything is good.. micro usb silver micro usbblac

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

    data science course

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

    ReplyDelete
  71. One word “informative”, you broke down precisely what I have been looking for. Looking forward to reading more in the future. https://royalcbd.com/faq/

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

    ReplyDelete
  73. The post is written in very a good manner and it contains many useful information for me. Tableau Data Blending

    ReplyDelete

Powered by Blogger.