Django urls: match '^$' and '^page/\d+)/$' in one urlpatterns -


i have view:

index(request,page=1) 

for now, use match both "" , "page/\d+" views.index:

url(r'^$', views.index) url(r'^page/(?p<page>\d+)/$', views.index) 

there many views need match both "" , "page/\d+", wonder if there easy way match 2 kinds of urls.thank you.

you can use following url.

url(r'^$|^page/(?p<page>\d+)/$', views.index) 

but have change view function follow:

def index(request, page):     if page none:         page = 1     ... 

note: adds complexity in urlpatterns forget because makes harder debug , read.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -