如何在模板上显示choicefield select小部件? [英] How to display choicefield select widget on template?
本文介绍了如何在模板上显示choicefield select小部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的观点
CHOICES = (('10','10'), ('20','20'),('30','30'), ('50','50'))
class Droplist (forms.Form):
number = forms.ChoiceField(choices = CHOICES)
def page_objects(request):
if request.method == 'POST': # If the form has been submitted...
form = Droplist(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
pass #pages = form.cleaned_data['value']
#return AutoPaginateNode(paginate_by=pages) # Redirect after POST
else:
form = Droplist() # An unbound form
return render_to_response('pagination.html', {'form': form })
这是我的模板:
<form action="/submit/" method="post">{% csrf_token %}
{{ form }}
<input type="submit" value="Select">
</form>
我如何呈现我的表单,因为我需要一个带有下拉菜单的模板选择框?我错过了什么?
how can i render my form, because i need to have a dropdown box with choices on template? what i've missed?
推荐答案
您需要使用 {{form.as_p}}
:
<form action="/submit/" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Select">
</form>
您也可以使用 {{form.as_table}}
以输出表行,但您需要提供自己的< table>
和 form.as_ul
输出列表项:
You can also use {{ form.as_table }}
to output table rows but you'll need to provide your own <table>
and form.as_ul
to output list items:
<form action="/submit/" method="post">{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Select">
</form>
这篇关于如何在模板上显示choicefield select小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文