views:

444

answers:

2

Hi

Currently, in my settings module I have this:

LOGIN_URL = '/login'

If I ever decide to change the login URL in urls.py, I'll have to change it here as well. Is there any more dynamic way of doing this?

+3  A: 

Settings IS where you are setting your dynamic login url. Make sure to import LOGIN_URL from settings.py in your urls.py and use that instead.

from projectname.settings import LOGIN_URL
AlbertoPL
But how do I fit that into `urlpatterns`? :/
Deniz Dogan
from django.conf.urls.defaults import *from projectname.settings import LOGIN_URLurlpatterns = patterns('', (r'^articles/2003/' + LOGIN_URL + '/$', 'news.views.special_case_2003'),
AlbertoPL
+1  A: 

This works for me ... with LOGIN_URL = '/accounts/login'

If the problem is that settings.py has ...

LOGIN_URL = '/login/'  # <-- remember trailing slash!

... but, urls.py wants ...

url(r'^login/$', 
      auth_views.login, {'template_name': '/foo.html'}, 
            name='auth_login'),

Then do this:

# - up top in the urls.py
from django.conf import settings

# - down below, in the list of URLs ...
# - blindly remove the leading '/' & trust that you have a trailing '/'
url(r'^%s$' % settings.LOGIN_URL[1:], 
      auth_views.login, {'template_name': '/foo.html'}, 
            name='auth_login'),

If you can't trust whomever edits your settings.py ... then check LOGIN_URL startswith a slash & snip it off, or not. ... and then check for trailing slash LOGIN_URL endswith a slash & tack it on, or not ... and and then tack on the '$'

joej