0
我在運行我的應用時出現「oReverseMatch at/filter」錯誤? 這是urls.py:'filter_display'與參數'()'和關鍵字參數'{'continent':'America'}'相反
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))
它,當我輸入 '8000/filter_display /歐洲/ localhost' 的工作。
該代碼在「filter_display」中完美工作。
但是當我嘗試使用「過濾器」功能視圖來傳遞參數我得到這個錯誤
我不明白你的意思是「傳遞參數使用過濾器函數):什麼代碼拋出該錯誤?你可以顯示回溯? – 2013-03-27 15:46:19
使用HttpResponse在過濾器視圖中重定向我傳遞參數(大陸)在url – Imoum 2013-03-27 15:50:08
嘗試刪除'args'參數。 – 2013-03-27 15:51:54