uWSGI Emperor和Django 1.6错误地读取urls.py

时间:2014-01-27 20:23:42

标签: python django nginx uwsgi

我正在为我的网络应用程序运行带有uWSGI和Django的Ubuntu服务器。

我让uWSGI在Emperor模式下运行,所以我所要做的就是添加一个ini文件,uWSGI会立即为我运行一切。我在服务器上有2个其他应用程序,运行方式相同,但出于某种原因,我今天提出的应用程序失败了。

我添加了包含以下内容的ini文件:

[uwsgi]
# variables
projectname = site
projectdomain = site.domain.com
base = /var/www/site.domain.com

# config
protocol = uwsgi
venv = %(base)/venv
pythonpath = %(base)/%(projectname)
module = %(projectname).wsgi
socket = /tmp/%(projectname).sock
chmod-socket = 666
logto = /var/log/uwsgi/%(projectname).log
plugins=python

目录结构的设置如下:

/var/www/site.domain.com
|- site
|--| (Django app stuff)
|- venv
|--bin, include, lib, local

“site”包含通常位于django-admin.py startproject中的所有内容,包括另一个名为“site”的文件夹,其中包含设置,网址, init 和wsgi文件。

“venv”是我存储虚拟环境的文件夹(来自python virtaulenv)

就像我说的那样,这个网站设置与我的其他网站完全一样,但是我在日志文件中不断收到此错误:

Traceback (most recent call last):
  File "/var/www/site.domain.com/venv/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    def _get_get(self):
  File "/var/www/site.domain.com/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 49, in load_middleware
    raise exceptions.ImproperlyConfigured('%s isn\'t a middleware module' % middleware_path)
  File "/var/www/site.domain.com/venv/local/lib/python2.7/site-packages/django/middleware/locale.py", line 24, in __init__
    translation.activate(language)
  File "/var/www/site.domain.com/venv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 350, in url_patterns
    except TypeError:
django.core.exceptions.ImproperlyConfigured: The included urlconf site.urls doesn't have any patterns in it
[pid: 2705|app: 0|req: 6/7] 131.118.85.3 () {38 vars in 702 bytes} [Mon Jan 27 20:10:28 2014] GET / => generated 0 bytes in 0 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)

有什么想法吗?

编辑: urls.py

from django.conf.urls import patterns, include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.conf import settings

admin.autodiscover()

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^ckeditor/', include('islam_site.ckeditor_urls')),
    url(r'^blog/', include('zinnia.urls')),
    (r'^comments/', include('django.contrib.comments.urls')),
    url(r'^comments/', include('django.contrib.comments.urls')),
    url(r'^', include('cms.urls')),
)

更新 我把应用程序从uwsgi皇帝中划出来,并使用gunicorn确保它不是皇帝的任何东西,这是输出:

gunicorn site.wsgi:application
2014-01-27 21:08:23 [336] [INFO] Starting gunicorn 18.0
2014-01-27 21:08:23 [336] [INFO] Listening at: http://127.0.0.1:8000 (336)
2014-01-27 21:08:23 [336] [INFO] Using worker: sync
2014-01-27 21:08:23 [341] [INFO] Booting worker with pid: 341
2014-01-28 02:08:27 [341] [ERROR] Error handling request
Traceback (most recent call last):
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 131, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    self.load_middleware()
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 49, in load_middleware
    mw_instance = mw_class()
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/middleware/locale.py", line 24, in __init__
    for url_pattern in get_resolver(None).url_patterns:
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 346, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 341, in urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/var/www/domain/site/site/urls.py", line 6, in <module>
    admin.autodiscover()
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 29, in autodiscover
    import_module('%s.admin' % app)
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/contrib/sites/admin.py", line 9, in <module>
    admin.site.register(Site, SiteAdmin)
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 92, in register
    admin_class.validate(model)
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/contrib/admin/options.py", line 105, in validate
    validator = cls.validator_class()
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/contrib/admin/validation.py", line 20, in __init__
    models.get_apps()
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/db/models/loading.py", line 139, in get_apps
    self._populate()
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/db/models/loading.py", line 75, in _populate
    self.load_app(app_name, True)
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
    models = import_module('%s.models' % app_name)
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/debug_toolbar/models.py", line 63, in <module>
    patch_root_urlconf()
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/debug_toolbar/models.py", line 51, in patch_root_urlconf
    reverse('djdt:render_panel')
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 480, in reverse
    app_list = resolver.app_dict[ns]
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 310, in app_dict
    self._populate()
  File "/var/www/domain/venv/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 262, in _populate
    for pattern in reversed(self.url_patterns):
  File "/var/www/domain/venv/local/lib/python2.7/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 site.urls doesn't have any patterns in it

看起来大多是同样的错误..

我正在考虑在服务器上逐步重建应用程序以避免此类问题。

1 个答案:

答案 0 :(得分:0)

我最终决定从头开始简单地重做应用程序,现在一切似乎都在运行。无论问题是什么,我都无法在新的应用程序中重现它。