Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL pattern with multiple names

Is it possible to define multiple names for the one URL pattern? I'd like to merge two views without finding all the references to each and changing them. Another benefit in keeping both names is in case I ever want to split them again later.

For example, merging

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')), #???
like image 992
jozxyqk Avatar asked Jul 13 '15 11:07

jozxyqk


1 Answers

No, it isn't possible to use a tuple for the url pattern's 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 have terminated the regexes with a dollar. Without it, the regex will match /profile/sonething-else/ as well as /profile/.

like image 179
Alasdair Avatar answered Nov 05 '22 07:11

Alasdair