#9941: {% url ... %} template tag may fail when not using a settings module
-----------------------------+----------------------------------------------
Reporter: Eftarjin | Owner: nobody
Status: new | Milestone:
Component: Template system | Version: 1.0
Keywords: | Stage: Unreviewed
Has_patch: 0 |
-----------------------------+----------------------------------------------
When using django.conf.settings.configure(...) instead of a settings
module as [http://docs.djangoproject.com/en/dev/topics/settings/#using-
settings-without-setting-django-settings-module documented],
settings.SETTINGS_MODULE is set to None.
The {% url ... %} template tag is implemented as following, in
django.template.defaulttags.URLNode.render :
{{{
# Try to look up the URL twice: once given the view name, and
again
# relative to what we guess is the "main" app. If they both fail,
# re-raise the NoReverseMatch unless we're using the
# {% url ... as var %} construct in which cause return nothing.
url = ''
try:
url = reverse(self.view_name, args=args, kwargs=kwargs)
except NoReverseMatch:
project_name = settings.SETTINGS_MODULE.split('.')[0]
try:
url = reverse(project_name + '.' + self.view_name,
args=args, kwargs=kwargs)
except NoReverseMatch:
if self.asvar is None:
raise
}}}
In some cases (for example in the admin templates), it will execute this :
'''settings.SETTINGS_MODULE.split('.')''' which raises '''!AttributeError:
'!NoneType' object has no attribute 'split''''.
Instead, it should check for settings.SETTINGS_MODULE being None before
using it.
As a workaround, set SETTINGS_MODULE to some module name. This module
needs to exist, as it is imported by other parts of Django, but does not
need to actually contain the settings (which are set with
django.conf.settings.configure)
--
Ticket URL: <http://code.djangoproject.com/ticket/9941>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---