This should be an easy question. I have two url patterns in Django:
url(r'^wiki/page/(?P<page_title>.*)', views.wiki_view, name = 'wiki_view'),
url(r'^wiki/page/$', views.wiki_page_index, name = 'wiki_page_index'),
When I visit /wiki/page/test, it takes me to views.wiki_view. This is correct. I need the first pattern to capture all characters after the "page/", which is why I used .*
When I visit /wiki/page/, it also takes me to views.wiki_view. This is incorrect.
I could alter the second url pattern to read:
url(r'^wiki/page/$', views.wiki_page_index, name = 'wiki_page_index'),
Thus, when I visit /wiki/page, it will take me to views.wiki_page_index. But I'd rather fix the problem instead of avoiding it.
How do I format the first url pattern so that it won't pick up the instance of /wiki/page/?
Change the first one to:
Place the second one before the current first one.
http://docs.djangoproject.com/en/dev/topics/http/urls/ ("Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL.")