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-users googlegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|