我正在尝试将数据从提交的表单发送到我的应用中的另一个视图,但
class FilterForm(forms.Form):
currency = forms.ChoiceField(choices=Currency_choices)
continent = forms.ChoiceField(choices=Select_continent())
country = forms.ChoiceField(choices=Select_country())
查看#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))
urls.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”在我的choicefield中返回所选值的键而不是值本身 这是我提交表格后得到的内容