0

网址.py

url(r'^kebreading/$', 'KEBReading1',name="kebreading"),
url(r'^kebreading/(?P<param>\w*)/(?P<date>\w*)/(?P<year>\w*)/(?P<month>\w*)/$', kEBReading1',name="kebreading")

我有一个视图,我将 5 个参数传递给它。当我不传递任何参数时,会调用相同的视图。但是即使我不传递任何参数,浏览器中的 url 也会附加五个斜杠。如何防止这种情况发生???

4

1 回答 1

0

You can use the regexp ? sign to create an optional group and use ?: so Django do not pass this group as an *arg parameter

Something like :

url(r'^kebreading/(?:(?P<param>\w*)/(?P<date>\w*)/(?P<year>\w*)/(?P<month>\w*)/)?$', kEBReading1',name="kebreading")

There is a similar question #2325433

于 2013-03-13T12:20:19.057 回答