Hi!
I'm trying to do a form, with gender choices. The user could choice between male or female.
What I have now in forms.py:
class GenderForm(forms.Form):
demo = DemoData.objects.all()
GENDER_CHOICES = [
('Male', 'Masculino'),
('Female', 'Feminino')]
gender = forms.ModelChoiceField(demo, widget=Select(), required=True)
choices_distlabel = [('', '')] + GENDER_CHOICES
gender.choices = choices_distlabel
in the template:
<form action="" method="post">
{% for field in form_gender %}
{{ field }}
{% endfor %}
<input type="submit" value="Submit" />
</form>
{% if idgender %}
<img src="/age_gender/{{ idgender }}.png" alt="Graph"/>
{% endif %}
the views:
if form_gender.is_valid():
gender = form_gender.cleaned_data['gender']
gender = gender.gender
if gender:
idgender = gender
return render_to_response('age.html', {'form_gender': form_gender, 'idgender': idgender })
the form is done and works, but the problem is when I click on the submit button nothing happen. He is not given me the information