运行我的应用程序时出现“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”中完美运行。
但是当我尝试使用视图中的“过滤器”函数传递参数时,我得到了这个错误