List Info

Thread: how to access the permalink-decorator in the settings.py with a named url pattern?




how to access the permalink-decorator in the settings.py with a named url pattern?
user name
2007-12-21 03:56:45
hi,

i have a name url pattern:

url( r'^login/', 'login', {'template_name':
"config/templates/
login.html"},name="config-login"),

this works perfectly in the template for

{% url config_login %}

but wouldn't it hurt the dry principle to write the
login-url in the
settings.py? right, so i want to do something like this:

from django.db.models import permalink
LOGIN_URL = permalink("config-login",())

but the first line raises an import error (don't know if i
can use
permalink just as url with a named url pattern):

 ./manage.py runserver
Error: Can't find the file 'settings.py' in the directory
containing
'./manage.py'. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings
module.
(If the file settings.py does indeed exist, it's causing an
ImportError somehow.)

tanks for your help!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: how to access the permalink-decorator in the settings.py with a named url pattern?
country flaguser name
Australia
2007-12-21 04:20:44

On Fri, 2007-12-21 at 01:56 -0800, Julian wrote:
> hi,
> 
> i have a name url pattern:
> 
> url( r'^login/', 'login', {'template_name':
"config/templates/
> login.html"},name="config-login"),
> 
> this works perfectly in the template for
> 
> {% url config_login %}
> 
> but wouldn't it hurt the dry principle to write the
login-url in the
> settings.py? right, so i want to do something like
this:
> 
> from django.db.models import permalink
> LOGIN_URL = permalink("config-login",())
> 
> but the first line raises an import error (don't know
if i can use
> permalink just as url with a named url pattern):

As a general rule, you can't import or use any code from
Django's core
in your settings file. There's too much chance of getting a
circular
dependency. A *lot* of core depends on django.conf.settings
being
available, which means your settings file must have been
completely
imported, not just "in the process of being
imported".

Short version: don't do that!

If you really want to avoid this small repetition, reverse
the
dependency:

in settings.py: LOGIN_URL='login/'

in urls.py:
        url(r'^%s$' % settings.LOGIN_URL, ....)
        
Or factor out the constant somewhere else. I don't
personally do this
because I like having all the URL patterns visible when I
read urls.py
and I rarely change my login url (it's either 'login/' or
'/', for me,
it seems). Might scratch your itch, though.

Regards,
Malcolm

-- 
Quantum mechanics: the dreams stuff is made of. 
http://www.pointy-s
tick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )