Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 如何在模板上显示choicefield select小部件?_Django_Forms_Drop Down Menu_Choicefield - Fatal编程技术网

Django 如何在模板上显示choicefield select小部件?

Django 如何在模板上显示choicefield select小部件?,django,forms,drop-down-menu,choicefield,Django,Forms,Drop Down Menu,Choicefield,我的看法是: 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 submi

我的看法是:

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>
{%csrf\u令牌%}
{{form}}

如何呈现我的表单,因为我需要一个下拉框,其中包含模板上的选项?我错过了什么?

您需要使用
{{{form.as\u p}}

<form action="/submit/" method="post">{% csrf_token %}
   {{ form.as_p }}
   <input type="submit" value="Select">
</form>

您可以在Django的文档中找到更多信息

它会在我的模板中创建下拉框吗?
<form action="/submit/" method="post">{% csrf_token %}
   <table>
       {{ form.as_table }}
   </table>
   <input type="submit" value="Select">
</form>