0

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.

Community
  • 1
  • 1
kartikmaji
  • 946
  • 7
  • 22
  • take a look at [pyuploadcare](https://github.com/uploadcare/pyuploadcare). it has django model for image uploads. – Dmitry Mukhin Dec 26 '14 at 12:27
  • That's okay. But, pyuploadcare is for django models(I think so). But, in my case, I am using ndb.Model to store my data. Can you be specific about how can I use pyuploadcare with my exisiting model(if there exist any possible solution). – kartikmaji Dec 27 '14 at 13:55
  • sorry about that! if you'll take a look at django's Uploadcare field , you'll see that this is in fact TextField, as only uploaded file URL is saved to DB. – Dmitry Mukhin Dec 27 '14 at 16:11

0 Answers0