我正在尝试将数据从提交的表单发送到我的应用程序中的另一个视图,但是
表格.py
class FilterForm(forms.Form):
currency = forms.ChoiceField(choices=Currency_choices)
continent = forms.ChoiceField(choices=Select_continent())
country = forms.ChoiceField(choices=Select_country())
视图.py
查看#1
def filtrer(request):
if request.method == 'POST':
form = FilterForm(request.POST)
if form.is_valid():
currency = form.cleaned_data['currency']
continent = form.cleaned_data['continent']
country = form.cleaned_data['country']
url = reverse('affiche_filter', args=(), kwargs={'continent':continent,'country':country,'currency':currency})
return HttpResponseRedirect(url)
else:
form =FilterForm()
return render_to_response('filter.html', {'form': form }, RequestContext(request))
视图#2
def affiche_filter(request,continent, country,currency):
data = Select_WHERE(continent, country, currency)
symbol = ConvertSymbol(currency)
return render_to_response('affiche_continent.html', {'data': data,'symbol':symbol }, RequestContext(request))
网址.py
urlpatterns = patterns('myform.views',
url(r'^filtrer$', 'filtrer'),
url(r'^affiche_filter/(?P<continent>[-\w]+)/(?P<country>[-\w]+)/(?P<currency>[-\w]+)/$', 'affiche_filter', name='affiche_filter'),
似乎我的选择字段中所选值的方法“form.cleaned_data”返回键不是值本身,这是我提交表单后得到的