I have been trying to implement ndb.BlobProperty() for my user in django with google app engine.
class UserData(ndb.Model):
email= ndb.StringProperty(required = True)
name = ndb.StringProperty(required = True)
created = ndb.DateTimeProperty(auto_now_add = True)
role = ndb.StringProperty(required = True)
blob_key = ndb.BlobProperty()
serving_url = ndb.StringProperty(indexed=False)
In the form, I have :
<form method="POST" action="{{upload_url}}" enctype="multipart/form-data">
{% csrf_token %}
<input name="name" type="text">
<input name="role" type="text">
<input name="profile_photo" type="file">
<input type="submit" value="Sign up" class="submit">
</form>
I am trying to upload using this code.
upload_files = str(request.FILES['profile_photo'])
u = UserData(email = user.email(),name=name,role=role)
if upload_files:
u.blob_key=upload_files
u.serving_url = images.get_serving_url(u.blob_key)
u.put()
And in my template, I am trying to show the image of the user.
<img src="{{people.profile_photo}}"></img>
<img src="{{people.get_serving_url}}"></img>
And both of them raises a 404 error.
I have already referred these sources, but none of them worked.
- Django on Google App Engine: cannot upload images
- How to upload a file using Django and Google App Engine Blobstore API
- How to upload a file using Django and Google App Engine Blobstore API
- How to upload file in django google app engine?
- Google App Engine (Python) - Uploading a file (image)
- Image Upload in Google App Engine