Issue
http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.Select
Here, it says I can do SELECT widgets. But how do I do that? It doesn't show any example on how to write that field in python.
<select>
<option>option 1</option>
<option>option 2</option>
</select>
Solution
class MyForm(forms.Form):
CHOICES = (('Option 1', 'Option 1'),('Option 2', 'Option 2'),)
field = forms.ChoiceField(choices=CHOICES)
print MyForm().as_p()
# out: <p><label for="id_field">Field:</label> <select name="field" id="id_field">\n<option value="Option 1">Option 1</option>\n<option value="Option 2">Option 2</option>\n</select></p>
Answered By - Yuji 'Tomita' Tomita
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.