我是django和mezzanine的新手,我对此有疑问。 我的项目名为bestsite,它基于Mezzanine CMS和nginx + uwsgi堆栈,在我尝试将项目(不移动)复制到另一个文件夹进行下一次开发并保留生产模式的初始文件夹之前,它工作正常。在开发文件夹中,我运行了manage.py syncdb,所以我认为它可能会影响django。因为我总是在uwsgi日志中看到异常:
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
有趣的是,我的项目在开发模式下工作正常(我的意思是manage.py runserver ...),但在nginx + uwsgi堆栈中不起作用。
我的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设置包含default mezzanine settings和我的附加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/'
)
答案 0 :(得分:1)
此波纹管堆栈跟踪段指出您的问题可能与调试工具栏应用程序有关。
...
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')
...
从堆栈跟踪的下方部分,我预计并非所有应用都具有正确的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):
...
您可以执行以下操作以找出导致问题的应用
如果由于Django应用程序导致问题导致问题,那么将其关闭将使您的系统正常工作。
当您处于生产模式时,未加载调试工具栏。因此,在生产模式下,您不会收到任何错误。
在开发模式下,调试工具栏正在尝试加载所有应用信息并落入由其他应用引起的某些陷阱。
祝你好运。