django dynamic choicefield中的选定选项

django dynamic choicefield中的选定选项,django,Django,我在django中创建了一个关键字过滤器 我的观点 #.............. if request.method == 'POST': form = FilterContentForm(request.POST) else: form = FilterContentForm() if len(keyword_dict)!= 0 and keyword_dict['customer_type'

我在django中创建了一个关键字过滤器

我的观点

#..............
if request.method == 'POST':
                 form = FilterContentForm(request.POST)
        else:
                 form = FilterContentForm()
        if len(keyword_dict)!= 0 and keyword_dict['customer_type']:
            list_customer = filter(keyword_dict['customer_type'])
            print keyword_dict
            return render_to_response('customers_filter.html', {"customers":list_customer,
                                                                     "form":form
                                                                     })
我的表格.py

#..............
CUSTOMER_TYPE_CHOICES = [('', 'All')] + [(customer_type.name, customer_type.name) for customer_type in Customer_Type.objects.all()]

class FilterContentForm(forms.Form):
    customer_type = forms.ChoiceField(choices=CUSTOMER_TYPE_CHOICES, required=False)  
    def __init__(self, *args, **kwargs):
        if 'label_suffix' not in kwargs:
            kwargs['label_suffix'] = ''
        super(FilterContentForm, self).__init__(*args, **kwargs)
我将表单值填充到模板中

{% extends "base.html" %}
{% block external %}
   <script type="text/javascript" src="/site_media/scripts/search.js"></script>
{% endblock %}

{% block content %}
{% block main %}
<form id="search-form" method="GET" action="." name="f">
{{ form.as_ul }}

<button id="filter">Filter</button>
</form>
<p>
<div id="search-results">
  {% if customers %}
   {% include 'customers.html' %}
  {% endif %}
</div>
{% endblock %}
{% endblock %}
这里的任何人都可以找到我的问题所在。我的错误是什么

<form id="search-form" method="GET" action="." name="f">
所以。。也许你需要method=“POST”

<form id="search-form" method="GET" action="." name="f">
if request.method == 'POST':