I have what I am sure is a very simple error in my django/python code. Essentially I'm trying (for now) to simply make a html-form that has a few drop-down lists and a file-upload capability. I have the following snippets of code:
views.py:
def convert(request):
if request.POST:
form = ConvertForm(request.POST,request.FILES)
if form.is_valid():
form.save()
# Change this to some result page,
# but for now, just see that we got the file
return HttpResponseRedirect('/convert/convert')
else:
form = ConvertForm()
args = {}
args.update(csrf(request))
args['form']=form
return render_to_response('convert.html',args)
in convert.html:
{% block content %}
<form action="/convert/convert/" method="post" enctype="multipart/form-data">{% csrf_token %}
<ul>
{{ form.as_ul }}
</ul>
<input type="submit" name="submit" value="Convert">
</form>
{% endblock %}
and in my forms.py:
from django import forms
class ConvertForm(forms.Form):
ff_from = forms.ChoiceField(choices=('a'))
ff_to = forms.ChoiceField(choices=('b'))
file = forms.FileField(max_length=200)
The error I'm getting is the following:
ValueError at /convert/convert/
need more than 1 value to unpack
Request Method: GET
Django Version: 1.5.2
Exception Type: ValueError
Exception Value:
need more than 1 value to unpack
Error during template rendering
In template /path/to/templates/convert.html, error at line 16
but I fail to understand why. I'm a newbie with django, but sort of used to python. Line 16 in convert.html is the line that has the
{{ form.as_ul }}
piece of code.
Right now I'm only trying to get the form to show on my website, much less than making it do something!
Let me know if this description is complete, not used to posting questions here! Thanks!