Imoum
Imoum

Reputation: 745

i can't posting data from view to another view using reverse and HttpResponseRedirect?

i'm trying to sending data from a submitted form to another view in my app but

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

view #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))

view#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'),

seems that the method "form.cleaned_data" return key of the selected value in my choicefield not the the value itself this what i got after submitted my form

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

Upvotes: 0

Views: 67

Answers (0)

Related Questions