开发者

How do I validate a Django form containing a file on App Engine with google-app-engine-django?

开发者 https://www.devze.com 2022-12-08 09:37 出处:网络
I have a model and form like so: class Image(BaseModel): original = db.BlobProperty() class ImageForm(ModelForm):

I have a model and form like so:

class Image(BaseModel):
  original = db.BlobProperty()

class ImageForm(ModelForm):
  class Meta:
    model = Image

I do the following in my view:

form = ImageForm(request.POST, request.FILES, instance=image)
if form.is_valid():

And I get:

AttributeError at /image/add/

'NoneType' object has no attribute 'validate'

Traced to:

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default开发者_运维百科.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/djangoforms.py in property_clean

  1. value: The value to validate. 606.
  2. Raises:
  3. forms.ValidationError if the value cannot be validated.
  4. """
  5. if value is not None:
  6. try:

  7. prop.validate(prop.make_value_from_form(value)) ...

  8. except (db.BadValueError, ValueError), e:

  9. raise forms.ValidationError(unicode(e)) 615. 616.
  10. class ModelFormOptions(object):
  11. """A simple class to hold internal options for a ModelForm class.

▼ Local vars

prop None

value InMemoryUploadedFile: Nearby.jpg (image/jpeg)

Any ideas how to get it to validate? It looks like FileField does not have a validate method, which Django expects...


It doesn't work with default django version. And bug is reported.

BTW, default installation raise other exeption. So possible problem with other part of your code.


The docs for the constructor say:

files: dict of file upload values; Django 0.97 or later only

Are you using Django 0.97? The bundled Django is 0.96, unless you explicitly select 1.0 or 1.1. Have you tried validating the form without the files parameter?

0

精彩评论

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