URL pattern with multiple names
Can multiple names be defined for one URL pattern? I would like to combine two views without finding all references to them and changing them. Another benefit of keeping both names is in case I ever want to split them later.
For example merge
url(r'^login/', TemplateView.as_view(template_name='login.html'), name='login'),
url(r'^profile/', TemplateView.as_view(template_name='profile.html'), name='profile'),
to
url(r'^profile/', TemplateView.as_view(template_name='profile.html'), name=('login', 'profile')), #???
+3
source to share
1 answer
No, you cannot use a tuple for the url pattern name. Just include the url pattern twice, with a different name each time.
url(r'^profile/$', TemplateView.as_view(template_name='profile.html'), name='login'),
url(r'^profile/$', TemplateView.as_view(template_name='profile.html'), name='profile'),
Note that I ended up using dollar regexes. Without it, the regex will match /profile/sonething-else/
as well /profile/
.
+4
source to share