アプリの実行中に "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」で完全に機能します。
しかし、ビューで「フィルター」関数を使用してパラメーターを渡そうとすると、このエラーが発生します