开发者

FileField() Error when trying to upload file using GAE and Django

开发者 https://www.devze.com 2023-02-09 02:36 出处:网络
Hello Stack Overflow community!! I am attempting to upload a file to GAE and I\'m using Django. When I run the following code it returns this error:

Hello Stack Overflow community!!

I am attempting to upload a file to GAE and I'm using Django. When I run the following code it returns this error:

Tried upload in module pathway.app.views. 
Error was: 'module' object has no attribute 'FileField'

When googling for a solution I found this开发者_如何学Go, but this issue should have been fixed by now right?

I am not sure at this point what I have done wrong, I am new to GAE,python and Django so any help would be appreciated!

And if anyone has a better solution to this problem, please tell me. Seems too much code for such a simple task.

models.py

class UploadModel(db.Model):
    title = db.StringProperty()
    file = db.BlobProperty()

    blobl = db.BlobProperty()

    modified_on = db.DateTimeProperty(auto_now_add= 1)
    modified_by = db.UserProperty()

views.py

def upload(request):
if request.method == 'POST':
     form = form.UploadFileForm(request.POST, request.FILES)
     if form.is_valid():
        handle_uploaded_file(models.db.Blob(request.FILES['file']))
        return HttpResponseRedirect('/success/url/')
else:
     form = form.UploadFileForm()

files = models.UploadModel.all().order('-modified_on').fetch(20)
payload = dict(files = files)
return render("upload.html",payload)

form.py

from django import newforms as forms import models

class UploadFileForm(forms.Form):
    title = forms.CharField(max_length=50)
    file  = forms.FileField()


You are using the version of Django included with Google App Engine, 0.96.4, which is four years old and comes from before the newforms library included support for file fields (and before it was renamed to simply forms).

Install an up-to-date Django version in your GAE project's directory and use that instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消