1

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/?

2 Answers 2

7

Change the first one to:

url(r'^wiki/page/(?P<page_title>.+)', views.wiki_view, name = 'wiki_view'),
Sign up to request clarification or add additional context in comments.

Comments

5

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.")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.