我不能使用reverse和HttpResponseRedirect将数据从视图发布到另一个视图?

时间:2013-04-01 11:40:56

标签: django cleaned-data

我正在尝试将数据从提交的表单发送到我的应用中的另一个视图,但

forms.py

class FilterForm(forms.Form):
    currency = forms.ChoiceField(choices=Currency_choices)
    continent = forms.ChoiceField(choices=Select_continent())   
    country = forms.ChoiceField(choices=Select_country())

views.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))     

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中返回所选值的键而不是值本身 这是我提交表格后得到的内容

This error is showed because the third parameter(here is'0') calculating the rate should be USD OR EURO not '0'

0 个答案:

没有答案