Reputation: 1254
In Django 1.7, how can I create only one url regex which matches all 3 following templates:
- /page/
- /page/{two characters}/
- /page.html
Many thanks.
Upvotes: 0
Views: 60
Reputation: 37934
try this
from django.views.generic import TemplateView
urlpatterns = patterns('',
url(r'^page/$', yourviews.page),
url(r'^page/(\w{2})/$', yourviews.page_detail),
url(r'^page.html$', TemplateView.as_view(template_name="page.html")),
)
UPDATE: I added TemplateView
for your page.html
, so you dont need to write views for it. this is one of the beauties of Django.
Upvotes: 2
Reputation: 5682
urls.py
url(r'^page/$', views.page),
url(r'^page/(\w{2})/$', views.page),
url(r'^page\\.html$', views.page),
views.py
def page(request, two_chars=''):
# ...
See this doc link.
Upvotes: 1