Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImproperlyConfigured: The included urlconf project.urls doesn't have any patterns in it (via patch_root_urlconf) #521

Closed
blueyed opened this issue Jan 6, 2014 · 17 comments

Comments

@blueyed
Copy link
Contributor

blueyed commented Jan 6, 2014

patch_root_urlconf appears to cause an ImproperlyConfigured error for me:

The included urlconf project.urls doesn't have any patterns in it

This happens after adding debug_toolbar to INSTALLED_APPS.

From the traceback it looks like the admin autodiscover triggers invocation of DDT's patching, but the project urlconf is still empty at that point.

apps/project/urls.py looks as follows:

# imports and autocomplete_light setup
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns(
    '',
    (r'^grappelli/', include('grappelli.urls')),
    url(r'^admin/', include(admin.site.urls)),

    # …
)

This does not happen with DDT 0.10.2.

I have also tried / are currently DDT master.

Django Version: 1.6.2.dev20140104173735

Traceback:
File "/home/daniel/src/django-stable/django/core/handlers/base.py" in get_response
  101.                 resolver_match = resolver.resolve(request.path_info)
File "/home/daniel/src/django-stable/django/core/urlresolvers.py" in resolve
  318.             for pattern in self.url_patterns:
File "/home/daniel/src/django-stable/django/core/urlresolvers.py" in url_patterns
  346.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/daniel/src/django-stable/django/core/urlresolvers.py" in urlconf_module
  341.             self._urlconf_module = import_module(self.urlconf_name)
File "/home/daniel/src/django-stable/django/utils/importlib.py" in import_module
  40.         __import__(name)
File "/home/daniel/projects/tmm/apps/project/urls.py" in <module>
  15. admin.autodiscover()
File "/home/daniel/src/django-stable/django/contrib/admin/__init__.py" in autodiscover
  29.             import_module('%s.admin' % app)
File "/home/daniel/src/django-stable/django/utils/importlib.py" in import_module
  40.         __import__(name)
File "/home/daniel/src/django-stable/django/contrib/auth/admin.py" in <module>
  182. admin.site.register(Group, GroupAdmin)
File "/home/daniel/src/django-stable/django/contrib/admin/sites.py" in register
  92.                     admin_class.validate(model)
File "/home/daniel/src/django-stable/django/contrib/admin/options.py" in validate
  105.         validator = cls.validator_class()
File "/home/daniel/src/django-stable/django/contrib/admin/validation.py" in __init__
  20.         models.get_apps()
File "/home/daniel/src/django-stable/django/db/models/loading.py" in get_apps
  139.         self._populate()
File "/home/daniel/src/django-stable/django/db/models/loading.py" in _populate
  75.                 self.load_app(app_name, True)
File "/home/daniel/src/django-stable/django/db/models/loading.py" in load_app
  99.             models = import_module('%s.models' % app_name)
File "/home/daniel/src/django-stable/django/utils/importlib.py" in import_module
  40.         __import__(name)
File "/home/daniel/.virtualenvs/tmm/src/django-debug-toolbar/debug_toolbar/models.py" in <module>
  63.     patch_root_urlconf()
File "/home/daniel/.virtualenvs/tmm/src/django-debug-toolbar/debug_toolbar/models.py" in patch_root_urlconf
  51.         reverse('djdt:render_panel')
File "/home/daniel/src/django-stable/django/core/urlresolvers.py" in reverse
  480.                 app_list = resolver.app_dict[ns]
File "/home/daniel/src/django-stable/django/core/urlresolvers.py" in app_dict
  310.             self._populate()
File "/home/daniel/src/django-stable/django/core/urlresolvers.py" in _populate
  262.         for pattern in reversed(self.url_patterns):
File "/home/daniel/src/django-stable/django/core/urlresolvers.py" in url_patterns
  350.             raise ImproperlyConfigured("The included urlconf %s doesn't have any patterns in it" % self.urlconf_name)

Exception Type: ImproperlyConfigured at /
Exception Value: The included urlconf project.urls doesn't have any patterns in it
@aaugustin
Copy link
Contributor

Does the "explicit setup" described in the documentation work for you?

@blueyed
Copy link
Contributor Author

blueyed commented Jan 6, 2014

@aaugustin yes.

@aaugustin
Copy link
Contributor

Which means you're seeing the documented behavior... I don't know how to improve this.

Let me know if you find a way around the circular import (send a pull request).

@amites
Copy link

amites commented Jan 16, 2014

For anyone else that runs into this adding the setting

DEBUG_TOOLBAR_PATCH_SETTINGS = False

fixed it for me

@aaugustin
Copy link
Contributor

Yes, but that's not enough, you also have to set up the Debug Toolbar explicitly.

In short: read the docs ;-)

@flaugher
Copy link

For what it's worth, I recently upgraded my MacBook Air to Mavericks and then rebuilt my virtual environment (with Django 1.5.1) and encountered this same "the included urlconf ... doesn’t have any patterns in it." error when I ran my nose tests. My screen was a sea of "F"s. But setting up the Debug Toolbar explicitly as aaugustin suggested solved the problem and all 232 of my tests now pass.

@aaugustin
Copy link
Contributor

When you re-installed your environment, you got the latest version.

You might want to pin your dependencies ;-)

itayB referenced this issue in itayB/placemarkr Jan 28, 2014
@blueyed
Copy link
Contributor Author

blueyed commented Apr 18, 2014

@aaugustin
Please consider re-opening it:

The error should be handled better, e.g. by catching ImproperlyConfigured and stating that the patching failed and how to resolve it (manual patching).

Currently it's very confusing, especially when it only happens when using the Django wsgi app, but not with "runserver".

FWIW here is a traceback, where debug_toolbar does not even appear (but toggling DEBUG_TOOLBAR_PATCH_SETTING triggered it):

ERROR django.request: Internal Server Error: /
Traceback (most recent call last):
  File "…/site-packages/django/core/handlers/base.py", line 139, in get_response
    response = response.render()
  File "…/site-packages/django/template/response.py", line 105, in render
    self.content = self.rendered_content
  File "…/site-packages/django/template/response.py", line 82, in rendered_content
    content = template.render(context)
  File "…/site-packages/django/template/base.py", line 140, in render
    return self._render(context)
  File "…/site-packages/django/test/utils.py", line 85, in instrumented_test_render
    return self.nodelist.render(context)
  File "…/site-packages/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)
  File "…/site-packages/django/template/base.py", line 854, in render_node
    return node.render(context)
  File "…/site-packages/django/template/loader_tags.py", line 123, in render
    return compiled_parent._render(context)
  File "…/site-packages/django/test/utils.py", line 85, in instrumented_test_render
    return self.nodelist.render(context)
  File "…/site-packages/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)
  File "…/site-packages/django/template/base.py", line 854, in render_node
    return node.render(context)
  File "…/site-packages/classytags/core.py", line 106, in render
    return self.render_tag(context, **kwargs)
  File "…/site-packages/sekizai/templatetags/sekizai_tags.py", line 76, in render_tag
    rendered_contents = nodelist.render(context)
  File "…/site-packages/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)
  File "…/site-packages/django/template/base.py", line 854, in render_node
    return node.render(context)
  File "…/site-packages/django/template/defaulttags.py", line 305, in render
    return nodelist.render(context)
  File "…/site-packages/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)
  File "…/site-packages/django/template/base.py", line 854, in render_node
    return node.render(context)
  File "…/site-packages/django/template/defaulttags.py", line 305, in render
    return nodelist.render(context)
  File "…/site-packages/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)
  File "…/site-packages/django/template/base.py", line 854, in render_node
    return node.render(context)
  File "…/site-packages/django/template/defaulttags.py", line 433, in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app)
  File "…/site-packages/django/core/urlresolvers.py", line 480, in reverse
    app_list = resolver.app_dict[ns]
  File "…/site-packages/django/core/urlresolvers.py", line 310, in app_dict
    self._populate()
  File "…/site-packages/django/core/urlresolvers.py", line 262, in _populate
    for pattern in reversed(self.url_patterns):
  File "…/site-packages/django/core/urlresolvers.py", line 350, in url_patterns
    raise ImproperlyConfigured("The included urlconf %s doesn't have any patterns in it" % self.urlconf_name)
ImproperlyConfigured: The included urlconf config.urls doesn't have any patterns in it

I suppose that Django 1.7 makes it easier to prevent this, but for 1.6 at least the error should be more descriptive.

As a workaround I can manually import "mainapp.admin" to prevent this circular import.

@aaugustin
Copy link
Contributor

I've spent way too much unpaid time attempting to fix this.

Feel free to submit a pull request.

@titovanton
Copy link

Hi!
Try this:

try:
    if sys.argv[1] == 'runserver' or sys.argv[1] == 'runserver_plus':
        DEBUG_TOOLBAR_PATCH_SETTINGS = DEBUG
    else:
        DEBUG_TOOLBAR_PATCH_SETTINGS = False
except IndexError:
        DEBUG_TOOLBAR_PATCH_SETTINGS = False

@schemacs
Copy link

@titovanton it works.

@rakeshgohel01
Copy link

The normal runserver works well in my case. I do not get this error, but when I change to server the website using uwsgi, I get this error.

Disabling debug toolbar it helps. I do not get any error, but this is not what I want. I want to run debug toolbar with.

I have tried individually with just DEBUG_TOOLBAR_PATCH_SETTINGS = DEBUG or DEBUG_TOOLBAR_PATCH_SETTINGS = False, but still the error happens.

Any further insight on this?

@titovanton
Copy link

@mocha384 also, if u have 30 sec page loads(when debug-toolbar is on), then the problem is django template system: some of the blocks or tags works 2 slow, for example: sorl-thumbnails (with Pillow backend). I cache this parts of templates code. To finde the bottleneck, disable all extra panels, unless 'template_timings_panel.panels.TemplateTimings.TemplateTimings', and relations...

@rakeshgohel01
Copy link

@titovanton thank you for the reply. let me try with your suggestion.

@rakeshgohel01
Copy link

@titovanton
My apology for late reply. I have checked your solution.
DEBUG_TOOLBAR_PATCH_SETTINGS = False along with explicit setup of DT fixed most of the issues related.

@VidJa
Copy link

VidJa commented Dec 12, 2014

How annoying this 'bug' Now I have to add an extra debug setting to my production urls.py or create another extra file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants