Urls doesn't have any patterns in it in django

366 views Asked by At

I'm new in django and mezzanine and i have issue with it. My project called bestsite and it based on Mezzanine CMS and nginx + uwsgi stack and it worked properly before I tried to copy project (not move) to another folder for next development and leave initial folder for production mode. In development folder I ran manage.py syncdb so I think it could affect django. Since that I always see exception in uwsgi log:

Traceback (most recent call last):
  File "/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    self.load_middleware()
  File "/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
    mw_instance = mw_class()
  File "/lib/python2.7/site-packages/django/middleware/locale.py", line 24, in __init__
    for url_pattern in get_resolver(None).url_patterns:
  File "/lib/python2.7/site-packages/django/core/urlresolvers.py", line 365, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/lib/python2.7/site-packages/django/core/urlresolvers.py", line 360, in urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
  File "/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "../bestsite/urls.py", line 10, in <module>
    admin.autodiscover()
  File "/lib/python2.7/site-packages/mezzanine/boot/__init__.py", line 77, in autodiscover
    django_autodiscover(*args, **kwargs)
  File "/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 29, in autodiscover
    import_module('%s.admin' % app)
  File "/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/lib/python2.7/site-packages/django/contrib/auth/admin.py", line 182, in <module>
    admin.site.register(Group, GroupAdmin)
  File "/lib/python2.7/site-packages/mezzanine/boot/lazy_admin.py", line 26, in register
    super(LazyAdminSite, self).register(*args, **kwargs)
  File "/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 92, in register
    admin_class.validate(model)
  File "/lib/python2.7/site-packages/django/contrib/admin/options.py", line 105, in validate
    validator = cls.validator_class()
  File "/lib/python2.7/site-packages/django/contrib/admin/validation.py", line 20, in __init__
    models.get_apps()
  File "/lib/python2.7/site-packages/django/db/models/loading.py", line 139, in get_apps
    self._populate()
  File "/lib/python2.7/site-packages/django/db/models/loading.py", line 75, in _populate
    self.load_app(app_name, True)
  File "/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
    models = import_module('%s.models' % app_name)
  File "/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/lib/python2.7/site-packages/debug_toolbar/models.py", line 9, in <module>
    dt_settings.patch_all()
  File "/lib/python2.7/site-packages/debug_toolbar/settings.py", line 238, in patch_all
    patch_root_urlconf()
  File "/lib/python2.7/site-packages/debug_toolbar/settings.py", line 226, in patch_root_urlconf
    reverse('djdt:render_panel')
  File "/lib/python2.7/site-packages/django/core/urlresolvers.py", line 507, in reverse
    app_list = resolver.app_dict[ns]
  File "/lib/python2.7/site-packages/django/core/urlresolvers.py", line 329, in app_dict
    self._populate()
  File "/lib/python2.7/site-packages/django/core/urlresolvers.py", line 267, in _populate
    for pattern in reversed(self.url_patterns):
  File "/lib/python2.7/site-packages/django/core/urlresolvers.py", line 369, in url_patterns
    raise ImproperlyConfigured("The included urlconf %s doesn't have any patterns in it" % self.urlconf_name)
django.core.exceptions.ImproperlyConfigured: The included urlconf bestsite.urls doesn't have any patterns in it
[pid: 1932|app: 0|req: 1/1] 195.19.132.64 () {40 vars in 1002 bytes} [Thu Nov 20 16:57:36 2014] GET / => generated 0 bytes in 490 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)
Traceback (most recent call last):
  File "/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    self.load_middleware()
  File "/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
    mw_instance = mw_class()
  File "/lib/python2.7/site-packages/django/middleware/locale.py", line 24, in __init__
    for url_pattern in get_resolver(None).url_patterns:
  File "/lib/python2.7/site-packages/django/core/urlresolvers.py", line 369, in url_patterns
    raise ImproperlyConfigured("The included urlconf %s doesn't have any patterns in it" % self.urlconf_name)
django.core.exceptions.ImproperlyConfigured: The included urlconf bestsite.urls doesn't have any patterns in it

Interestingly that my project works fine in development mode (i mean manage.py runserver ...), but doesn't work in nginx + uwsgi stack.

My uwsgi ini:

[uwsgi]
socket = /tmp/best.sock
virtualenv = /
chdir = /usr/share/mezzanine/bestsite/
wsgi-file = /usr/share/mezzanine/bestsite/wsgi.py
pythonpath = ..
env = DJANGO_SETTINGS_MODULE=bestsite.settings
vacuum = True
master = true
chmod-socket = 666
worker = 1
processes = 1
enable-threads = true
daemonize=running.log
pidfile=/tmp/bestsite.pid

Nginx conf:

upstream django {
    server unix:///tmp/best.sock;
}

server {
    listen      80;
    server_name ...;
    charset     utf-8;
    client_max_body_size 75M;   # adjust to taste

    location /static {
        alias /usr/share/mezzanine/bestsite/static;
    }

    location / {
        uwsgi_pass  django;
        include     /usr/share/mezzanine/bestsite/uwsgi_params;
    }
}

Django settings consists of default mezzanine settings and my additional local_settings.py:

PROJECT_ROOT = "/usr/share/mezzanine/bestsite"
DEBUG = True

SECRET_KEY = ...
NEVERCACHE_KEY = ...

DATABASES = {
    ...
}

ALLOWED_HOSTS = [
    ...
]

COMMENTS_USE_RATINGS = False
COMMENTS_ACCOUNT_REQUIRED = True
PAGES_PUBLISHED_INCLUDE_LOGIN_REQUIRED = False
USE_I18N = True
LANGUAGE_CODE = "ru"
LOCALE_PATHS = (
    '/usr/share/mezzanine/bestsite/locale/'
)
1

There are 1 answers

0
Ibrahim On BEST ANSWER

This bellow stack trace segment has pointing that your problem might have relation to debug toolbar app.

        ...
        File "/lib/python2.7/site-packages/debug_toolbar/models.py", line 9, in <module>
            dt_settings.patch_all()
          File "/lib/python2.7/site-packages/debug_toolbar/settings.py", line 238, in patch_all
            patch_root_urlconf()
          File "/lib/python2.7/site-packages/debug_toolbar/settings.py", line 226, in patch_root_urlconf
            reverse('djdt:render_panel')
        ...

From bellow portion of your stack trace, I am expecting not all of your apps has correct urls.py.

         ...
          File "/lib/python2.7/site-packages/django/core/urlresolvers.py", line 329, in app_dict
            self._populate()
          File "/lib/python2.7/site-packages/django/core/urlresolvers.py", line 267, in _populate
            for pattern in reversed(self.url_patterns):
        ...

You can do the following to trace out which apps are causing the problem

  • Turn on debug_toolbar app.
  • Manually turning off other apps one by one

If You problem is causing because of one the Django apps, then with turning it off will make your system work.

Debug toolbar is not loaded while you are in production mode. So you are not getting any error while on Production mode.

In Development mode, debug toolbar is trying to load all apps info and falling on some trap caused by other apps.

Best of Luck.