DjDT reverses url before models are loaded in urls.py
See original GitHub issueInitially, I got this error when trying to set up a new project with Django Debug Toolbar and uwsgi:
NoReverseMatch at /
u'djdt' is not a registered namespace
This occurred in uwsgi first, which does not load the models beforehand. Later, was able to reproduce it by patching django runserver with the following:
diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py
index 391e0b4..02dadc7 100644
--- a/django/core/management/commands/runserver.py
+++ b/django/core/management/commands/runserver.py
@@ -89,7 +89,7 @@ class Command(BaseCommand):
quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
self.stdout.write("Validating models...\n\n")
- self.validate(display_num_errors=True)
+ #self.validate(display_num_errors=True)
self.stdout.write((
"%(started_at)s\n"
"Django version %(version)s, using settings %(settings)r\n"
I put a pdb before the url patching in models.py, and got this:
/usr/lib64/python2.7/threading.py(784)__bootstrap()
-> self.__bootstrap_inner()
/usr/lib64/python2.7/threading.py(811)__bootstrap_inner()
-> self.run()
/usr/lib64/python2.7/threading.py(764)run()
-> self.__target(*self.__args, *self.__kwargs)
/usr/lib64/python2.7/SocketServer.py(593)process_request_thread()
-> self.finish_request(request, client_address)
/usr/lib64/python2.7/SocketServer.py(334)finish_request()
-> self.RequestHandlerClass(request, client_address, self)
django/core/servers/basehttp.py(150)__init__()
-> super(WSGIRequestHandler, self).__init__(*args, **kwargs)
/usr/lib64/python2.7/SocketServer.py(649)__init__()
-> self.handle()
/usr/lib64/python2.7/wsgiref/simple_server.py(124)handle()
-> handler.run(self.server.get_app())
/usr/lib64/python2.7/wsgiref/handlers.py(85)run()
-> self.result = application(self.environ, self.start_response)
django/contrib/staticfiles/handlers.py(72)__call__()
-> return self.application(environ, start_response)
django/core/handlers/wsgi.py(255)__call__()
-> response = self.get_response(request)
django/core/handlers/base.py(103)get_response()
-> resolver_match = resolver.resolve(request.path_info)
django/core/urlresolvers.py(319)resolve()
-> for pattern in self.url_patterns:
django/core/urlresolvers.py(347)url_patterns()
-> patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
django/core/urlresolvers.py(342)urlconf_module()
-> self._urlconf_module = import_module(self.urlconf_name)
django/utils/importlib.py(35)import_module()
-> __import__(name)
project/urls.py(5)<module>()
-> admin.autodiscover()
mezzanine/boot/__init__.py(76)autodiscover()
-> django_autodiscover(*args, **kwargs)
django/contrib/admin/__init__.py(29)autodiscover()
-> import_module('%s.admin' % app)
django/utils/importlib.py(35)import_module()
-> __import__(name)
django/contrib/auth/admin.py(179)<module>()
-> admin.site.register(Group, GroupAdmin)
mezzanine/boot/lazy_admin.py(22)register()
-> super(LazyAdminSite, self).register(*args, **kwargs)
django/contrib/admin/sites.py(98)register()
-> validate(admin_class, model)
django/contrib/admin/validation.py(22)validate()
-> models.get_apps()
django/db/models/loading.py(134)get_apps()
-> self._populate()
django/db/models/loading.py(72)_populate()
-> self.load_app(app_name, True)
django/db/models/loading.py(96)load_app()
-> models = import_module('.models', app_name)
django/utils/importlib.py(35)import_module()
-> __import__(name)
debug_toolbar/models.py(63)<module>()
-> patch_root_urlconf()
> debug_toolbar/models.py(51)patch_root_urlconf()
-> reverse('djdt:render_panel')
(Pdb) reverse('djdt:render_panel')
** ImproperlyConfigured: The included urlconf project.urls doesn't have any patterns in it
It seems like admin.autodiscover() loads the models in the urls.py, which subsequently forces debug_toolbar.models to reverse a url despite urls.py not having any urls in it yet.
Issue Analytics
- State:
- Created 10 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
After adding django-debug to App, getting "'djdt' is not a ...
What I've tried: changing the order of these Middleware entries in settings.py (first, middle and last); adding a namespace attribute to my ...
Read more >"Conflicting models in application" RuntimeError for same ...
When using a relative import in tests.py then, the model appears to get ... But if the checks are run in models and...
Read more >[Django] #22280: "Conflicting models in application ...
tests.py file: `from .models import Model`. I am running manage.py from the first "project" directory. `sys.path` contains the directory ` ...
Read more >Things You Must Know About Django Admin As Your App ...
We use Django 1.8, Python 3.4 and PostgreSQL 9.4. ... Before We Start ... Create a link to a detail page of a...
Read more >django-hosts — django-hosts 3.1.dev1+gad41990 ...
This Django app routes requests for specific hosts to different URL schemes defined in ... You can use your urls.py as a template...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@jonykwa Did you try adding this to your project’s urls.py?
Just to add some simple thing to check when you get this error. If you add the urlpattern before your own url patterns, don’t forget to have your own urlpattern appended: