django - 设置 uWSGI 和 Django 应用

标签 django uwsgi

我正在尝试按照本指南中的步骤操作:http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

在我什至进入 nginx 部分之前,我试图确保 uWSGI 正常工作

我的文件夹结构是 srv/www/domain/projectdatabank/

项目数据库文件夹包含我的 manage.py 文件

我的 wsgi.py 文件如下所示:

import os
import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "databank.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

我进入 projectdatabank 文件夹并运行以下命令
uwsgi --http :8000 --wsgi-file projectdatabank/databank/wsgi.py

当我转到网页时,我收到此错误
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-3) on 06 July 2013 00:16:13
os: Linux-3.8.4-linode50 #1 SMP Mon Mar 25 15:50:29 EDT 2013
nodename: 
machine: i686
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /srv/www/databankinfo.com
detected binary path: /usr/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 1024
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uWSGI http bound on :8000 fd 4
spawned uWSGI http 1 (pid: 10091)
uwsgi socket 0 bound to TCP address 127.0.0.1:47129 (port auto-assigned) fd 3
Python version: 2.6.6 (r266:84292, Feb 21 2013, 23:54:59)  [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x8cf8598
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 64000 bytes (62 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x8cf8598 pid: 10090 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 10090, cores: 1)
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 236, in __call__
    self.load_middleware()
  File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 45, in load_middleware
    for middleware_path in settings.MIDDLEWARE_CLASSES:
  File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 53, in __getattr__
    self._setup(name)
  File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 48, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/lib/python2.6/site-packages/django/conf/__init__.py", line 134, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'databank.settings' (Is it on sys.path?): No module named databank.settings
[pid: 10090|app: 0|req: 1/1] 66.56.35.151 () {38 vars in 669 bytes} [Tue Jul  9 17:34:52 2013] GET / => generated 0 bytes in 1 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)

但是我知道 settings.py 与 wsgi.py 存在于同一目录中

最佳答案

您需要为您的 uwsgi 提供一个额外的参数。称呼:

--chdir /path/to/your/project/

关于django - 设置 uWSGI 和 Django 应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17554668/

相关文章:

python - uwsgi-nginx-flask : unable to load app 0 (mountpoint ='' ) (callable not found or import error)

python - 如何告诉 uWSGI 优先选择进程而不是线程来实现负载平衡

django - uWSGI与Docker的Supervisord一起提供的应用程序

python - 无法使用views.py文件转储mysql数据库

python - Django ContextMixin 'super' 对象没有属性 'get_context_data'

django - 如何在 OS X Server 上部署 django 应用程序?

python - 在 Django 休息框架中按通用关系的名称设置内容类型

python - memcached 可以有效处理多大的数据?

python项目导入uwsgi如何进行单元测试?

python - 从 uwsgi 调用子进程 sudo