I am mapping a dynamic url parameter such as a pagename in my application like so myapp.com/[pagenamehere] My urls.py for this looks like:
url(r'^(?P<pagename>[a-zA-Z0-9_.-]*)/$',
views.all_pagenames,
name='all_pagenames')
However, the urls for myapp.com/login, myapp.com/register, myapp.com/about etc are already mapped in the urls.py file like so, for example:
url(r'^about/$', views.about, name='about')
How can I revise the dynamic url for pagenames so that words such as ‘login’ ‘about’ etc are excluded from possible pagename parameters and don’t forward to the “all_pagenames” function in the views and instead goes to the appropriate function?
Django will try each url pattern in definition order, so you don't have to worry about "exluding" your other urls, all you need is to make sure you define them before the catch-all "pagename" url pattern:
url(r'^about/$', views.about, name='about')
url(r'^login/$', views.login, name='login')
# etc
# and last:
url(r'^(?P<pagename>[a-zA-Z0-9_.-]*)/$',
views.all_pagenames, name='all_pagenames')
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments