使用Google App Engine在django上传和显示图像

时间:2014-12-18 15:58:26

标签: python django google-app-engine file-upload

我一直在尝试使用谷歌应用引擎为django中的用户实现ndb.BlobProperty()。

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)

在表格中,我有:

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

我正在尝试使用此代码上传。

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()

在我的模板中,我试图显示用户的图像。

<img src="{{people.profile_photo}}"></img>
<img src="{{people.get_serving_url}}"></img>

他们两人都提出了404错误。

我已经提到了这些来源,但没有一个有效。

0 个答案:

没有答案