This code is in django.core.urlresolvers:
def _get_urlconf_module(self):
try:
return self._urlconf_module
except AttributeError:
try:
self._urlconf_module = __import__(self.urlconf_name, {}, {}, [''])
except Exception, e:
# Either an invalid urlconf_name, such as "foo.bar.", or some
# kind of problem during the actual import.
raise ImproperlyConfigured, "Error while importing URLconf %r: %s" % (self.urlconf_name, e)
return self._urlconf_module
urlconf_module = property(_get_urlconf_module)
It was sufficient for configuration files (almost) without imports:
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^articles/2003/$', 'news.views.special_case_2003'),
(r'^articles/(\d{4})/$', 'news.views.year_archive'),
(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'),
)
But now it is possible to use this file:
from django.conf.urls.defaults import *
from news import views
urlpatterns = patterns('',
(r'^articles/2003/$', views.special_case_2003),
(r'^articles/(\d{4})/$', views.year_archive),
(r'^articles/(\d{4})/(\d{2})/$', views.month_archive),
(r'^articles/(\d{4})/(\d{2})/(\d+)/$', views.article_detail),
)
This file imports views, views probably import models and there are many possibilities for syntax errors. It is very difficult to tell where the error is.
So I would like to propose to show original exception in the debug mode:
def _get_urlconf_module(self):
try:
return self._urlconf_module
except AttributeError:
try:
self._urlconf_module = __import__(self.urlconf_name, {}, {}, [''])
except Exception, e:
# Either an invalid urlconf_name, such as "foo.bar.", or some
# kind of problem during the actual import.
from django.conf import settings
if settings.DEBUG:
raise
else:
raise ImproperlyConfigured, "Error while importing URLconf %r: %s" % (self.urlconf_name, e)
return self._urlconf_module
urlconf_module = property(_get_urlconf_module)