0

アプリの実行中に "oReverseMatch at /filter" エラーが発生しましたか? これは urls.py です:

urlpatterns = patterns('myform.views',
                       url(r'^contact$', 'contact'),
                       url(r'^affiche$', 'affiche'),
                       url(r'^add$', 'add'),
                       url(r'^filter$', 'filter'),
                       url(r'^filter_display/(?P<continent>[-\w]+)/$', 'filter_display',name='FilterDisplay'),

これは私のview.pyです:

class FilterForm(forms.Form):
    Continent = forms.ChoiceField(choices=Select_continent())   
    Country = forms.ChoiceField(choices=Select_country())
    City = forms.ChoiceField(choices=Select_city())
    Server_Adress = forms.ChoiceField(choices=Select_adress())

def filter(request):
    if request.method == 'POST':                                                                                                                                                 
        form = FilterForm(request.POST)                                                                                                                                            
        if form.is_valid() :
            Continent = form.cleaned_data['Continent']
            Country = form.cleaned_data['Country']
            City = form.cleaned_data['City']
            Server_Adress = form.cleaned_data['Server_Adress']
            #Continent = dict(form1.fields['Continent'].choices)[Continent]
            #Country = dict(form1.fields['Country'].choices)[Country]
            #City = dict(form1.fields['City'].choices)[City]
            #Server_Adress = dict(form1.fields['Server_Adress'].choices)[Server_Adress]
            url = reverse('filter_display', args=(),   kwargs={'continent': 'America',})
            return HttpResponseRedirect(url)
    else:
        form = FilterForm()
    return render_to_response('filter.html', { 'form': form }, RequestContext(request))     


def filter_display(request, continent):
        if request.method == 'POST':                                                                                                                                                 
            form1 = FilterForm(request.POST)                                                                                                                                            
            if form1.is_valid() :
                Continent = form1.cleaned_data['Continent']
                Country = form1.cleaned_data['Country']
                City = form1.cleaned_data['City']
                Server_Adress = form1.cleaned_data['Server_Adress']
        else:
            form1 = FilterForm()
        data = Select_WHERE(continent)
        return render_to_response('affiche_continent.html', {'form1':form1, 'data':data }, RequestContext(request))  

URL に「localhost:8000/filter_display/EUROPE/」と入力すると機能します。
コードは「filter_display」で完全に機能します。
しかし、ビューで「フィルター」関数を使用してパラメーターを渡そうとすると、このエラーが発生します

4

1 に答える 1

2

nameその URL に を指定したので、 への呼び出しでそれを使用する必要がありreverseます。

url = reverse('FilterDisplay', kwargs={'continent': 'America',})
于 2013-03-27T16:01:40.320 に答える