I only want to create
forms.ChoiceField(choices=CHOICES)
field to create a simple select html item. Because this is all I want, I don’t really want to create a new form class etc. So is there a way to render only one form field in django templates without creating/passing in a form?
for example:
def index(request, template_name="main/index.html"):
select = forms.ChoiceField(choices=CHOICES)
return render_to_response(template_name, locals(), context_instance=RequestContext(request))
is there a way I can do {{ select }} in the django template or something like that to create a select item?
Thanks in advance!
If you don’t need an entire Django form class, I would recommend just passing the list of choices to the template and iterating over it to create the
<option />tags for the<select>. That’s a lot easier than trying to render a form widget at the template level, imo.