I've created a wizard form that worked up until I added an ImageField.
When I got to submit the form with an image file chosen I get returned to the page saying the ImageField is required.
I've set up the MEDIA_ROOT and have that working.
Here are the snippets of code I think are in question:
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
I get this issue:
I can't seem to find the problem on the internet. I'm using Django 1.6.1
The Django Docs specify that there is unfortunately a little work to do when binding an uploaded file to a form field:
https://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-files-to-a-form
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.