In this post of Python Django with Fire-base series i will continue Firebase storage, In previous post we have covered uploading data to firebase storage using a simple form by which we can upload an image to Firebase storage, here i will show how we can retrieve that image from storage to a html page (specifically Django Template).
Insights :
Retrieving image to a Django template needs a image URL which can be attached to img src tag. In previous post, while uploading image to firebase storage we have also saved url to firebase database in specific logged in user ID.
Firebase Database Sample :
Showing for getting this image url we need to use pyrebase library shallow function for getting all report ids in a list, and need to run nested loop for getting content from each report id and at last we will separate image url and send it 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
Views.py :
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() | ||
img_url = database.child('users').child(a).child('reports').child(time).child('url').get().val() | ||
print(img_url) | ||
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,'i':img_url}) |
Template:
post_check.html
So, that’s it for Firebase storage with Python Django, in next post we’ll see how to implement Firebase cloud messaging with Python django
Get whole Django project source code here