Problems with Django Form Processing

4 views
Skip to first unread message

zhyr28

unread,
Jan 17, 2012, 2:05:07 AM1/17/12
to Django users
Hi all, I want to develop a survey app that has ten radio selects.
After people submit the survey, the data will be processing and then
output the result. I met a problem when I was trying to process the
data from the form. Here is the code:

forms.py: contains the survey questions.
QUESTION_ONE= (('4','Black',), ('3', 'Red',), ('2', 'Green',), ('1',
'Purple',))
lass SurveyForm(forms.Form):
q1 = forms.ChoiceField(
widget=forms.RadioSelect, # radio select
label=u" 1. What's your prefered colour?",
choices = QUESTION_ONE # four choices
)

views.py
def take_survey(request):
if request.method=='POST':
form = SurveyForm(request.POST)
if form.is_valid():
p1 = form.cleaned_data['q1'] # get the result of input
p = p1[0] #get
the number
if p>2:
return HttpResponseRedirect('a.html') # if
user choose black or red, then redirect user to a.html

i cannot get the correct result, but I do not know which step is
wrong. Hope someone could help me. Thank you.

Jason

unread,
Feb 7, 2012, 1:02:25 AM2/7/12
to Django users
Your numerical values might be considered strings for that comparison.
Try:

if int(p) > 2:
...
Reply all
Reply to author
Forward
0 new messages