简体   繁体   English

Django表单图像字段出现在self.data中,但没有出现在self.cleaned_data中

[英]Django form imagefield appear in self.data but none in self.cleaned_data

I have a modelForm and imagefield in model. 我在模型中有一个modelForm和imagefield。 Everything seems ok in form. 一切看起来都不错。

I put a debugger in save method of form. 我在形式的保存方法中放入了调试器。

self.data appears like below self.data如下所示

<QueryDict: {u'city': [u'19105'], u'surname': [u'VARGI'], u'name': [u'Tuna'], u'image': [u'996884_10151559653258613_1077262085_n.jpg'], u'user': [u'1'], u'interest': [u''], u'csrfmiddlewaretoken': [u'pHAfb5EJBc7N3Xa8YxTQKRrSDeLdBugh'], u'biography': [u'asdasdasdasdasda']}>

and self.is_valid() is True and self.errors is empty 并且self.is_valid()为True和self.errors为空

but my self.clean() is 但是我的self.clean()是

{'city': <City: Ankara, Ankara, Turkey>, 'is_featured': False, 'biography': u'asdasdasdasdasda', 'surname': u'VARGI', 'name': u'Tuna', 'image': None, 'is_active': False, 'user': <Member: tuna>, 'interest': [], 'email': u'', 'categories': []}

image come as None. 图像作为无。 Any ideas ? 有任何想法吗 ?

By the way, i can add an image from django-admin 顺便说一句,我可以从django-admin添加图像

Make sure you have enctype="multipart/form-data" set on your html tag. 确保在html标记上设置了enctype="multipart/form-data" And make sure you pass request.FILES into the form. 并确保将request.FILES传递到表单中。 For example: form = MyAwesomeForm(request.POST, request.FILES) 例如: form = MyAwesomeForm(request.POST, request.FILES)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM