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
- value: The value to validate. 606.
- Raises:
- forms.ValidationError if the value cannot be validated.
- """
- if value is not None:
try:
prop.validate(prop.make_value_from_form(value)) ...
except (db.BadValueError, ValueError), e:
- raise forms.ValidationError(unicode(e)) 615. 616.
- class ModelFormOptions(object):
- """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?
精彩评论