Django,Gunicorn:无法导入名称视图

时间:2014-05-21 16:02:18

标签: python django bash nginx gunicorn

我正在尝试与Nginx和Gunicorn建立一个Django项目。我想我遇到了一些我似乎无法弄清楚的路径问题。

我的root virtualenv目录:/var/www/webapps/testapp/

如果我从gunicorn mysite.wsgi:application --bind 0.0.0.0:8001运行/var/www/webapps/testapp/testapp/(对命名约定道歉......)它有效!

但是......如果我尝试从bash脚本运行我正在使用启动gunicorn项目似乎运行但是当我尝试加载页面时我得到这些错误:

ImportError at /home/
cannot import name views
Request Method: GET
Request URL:    https://URL/home/
Django Version: 1.6.2
Exception Type: ImportError
Exception Value:    
cannot import name views
Exception Location: /var/www/webapps/testapp/testapp/testapp/urls.py in <module>, line 2
Python Executable:  /var/www/webapps/testapp/bin/python2.7
Python Version: 2.7.6
Python Path:    
['/var/www/webapps/testapp/testapp',
 '/var/www/webapps/testapp/bin',
 '/var/www/webapps/testapp/testapp',
 '/var/www/webapps/testapp/bin',
 '/var/www/webapps/testapp/lib/python27.zip',
 '/var/www/webapps/testapp/lib/python2.7',
 '/var/www/webapps/testapp/lib/python2.7/plat-linux2',
 '/var/www/webapps/testapp/lib/python2.7/lib-tk',
 '/var/www/webapps/testapp/lib/python2.7/lib-old',
 '/var/www/webapps/testapp/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7',
 '/usr/local/lib/python2.7/plat-linux2',
 '/usr/local/lib/python2.7/lib-tk',
 '/var/www/webapps/testapp/lib/python2.7/site-packages']
Server time:    Wed, 21 May 2014 15:26:45 +0000

我使用的bash脚本如下:

#!/bin/bash

NAME="testapp2"                                       # Name of the application
DJANGODIR=/var/www/webapps/testapp/testapp          # Django project directory
SOCKFILE=/var/www/webapps/testapp/run/gunicorn.sock  # we will communicte using this unix socket
USER=testappuser                                     # the user to run as
GROUP=webapps                                        # the group to run as
NUM_WORKERS=16                                       # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=mysite.settings              # which settings file should Django use
DJANGO_WSGI_MODULE=mysite.wsgi                      # WSGI module name
PYTHONPATH=/var/www/webapps/testapp/bin`

echo "Starting $NAME as "whoami"

# Activate the virtual environment
cd $DJANGODIR
source ../bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH`

# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --log-level=debug \
  --bind=unix:$SOCKFILE

使用bash脚本不起作用,我似乎无法弄清楚原因。有人可以帮忙吗?

由于

1 个答案:

答案 0 :(得分:0)

原来问题在于目录权限和运行gunicorn进程的用户。

现在全部排序,谢谢!