我创建了一个向导表单,直到我添加了ImageField。
当我提交选择了图像文件的表单时,我会返回页面,说明需要ImageField。
我已经设置了MEDIA_ROOT并且正常工作。
以下是我认为有问题的代码片段:
models.py
# CreatePuzzleWizard forms
class uploadForm(forms.Form):
puzzle_image = forms.ImageField()
puzzle_name = forms.CharField(max_length=30, widget=forms.TextInput(attrs={'class':'form-control'}))
puzzle_description = forms.CharField(max_length=300, widget=forms.TextInput(attrs={'class':'form-control'}))
views.py
class CreatePuzzleWizard(SessionWizardView):
template_name = "create.html"
file_storage = FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT, 'tmp'))
def done(self, form_list, **kwargs):
form_data = process_form_data(form_list)
return render('complete.html', {'form_list', form_list})
def process_form_data(form_list):
form_data = [form.cleaned_data for form in form_list]
# do stuff with form data
return form_data
我遇到了这个问题:
我似乎无法在互联网上找到问题。我正在使用Django 1.6.1
答案 0 :(得分:1)
Django Docs指出,在将上传的文件绑定到表单字段时,遗憾的是还有一些工作要做:
https://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-files-to-a-form