繁体   English   中英

Django&WSGI-导入错误找不到模块django

[英]Django & WSGI - Import Error Can't find module django

我正在为django项目配置的游民区中设置本地开发环境。 因此,virtualenv在这一点上实际上并没有太多使用,所以我只是将所有模块安装在requirements.txt中

Django==1.7.3
Pillow==2.7.0
django-angular==0.7.10
djangorestframework
markdown
django-filter
mysqlclient==1.3.4

我的问题是,无论我尝试了什么,我始终如一地

Traceback (most recent call last):
File "/home/vagrant/photoapp.com/photoapp/wsgi.py", line 17, in <module>
from django.core.wsgi import get_wsgi_application
   ImportError: No module named 'django'

应用程序文件夹结构为:

photoapp.com/
├── app
│   ├── admin.py
│   ├── __init__.py
│   ├── migrations
│   │   └── __init__.py
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── manage.py
├── photoapp
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── requirements.txt
├── templates
└── Vagrantfile

使用标准的wsgi.py:

import os
import sys

sys.path.append("/home/vagrant/photoapp.com")
sys.path.append("/home/vagrant/photoapp.com/photoapp")

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "photoapp.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

和一个虚拟主机文件:

<VirtualHost *:80>
    ServerName      dev.photoapp.com
    ServerAlias     photoapp.com

    DocumentRoot    "/home/vagrant/photoapp.com"

    alias /photos/  "/home/vagrant/photos/"
    alias /static/  "/home/vagrant/photoapp.com/static/"

    <Directory /home/vagrant/photoapp.com/static>
            Require all granted
    </Directory>

    <Directory /home/vagrant/photos>
            Require all granted
    </Directory>

    <Directory /home/vagrant/photoapp.com/photoapp>
            <Files wsgi.py>
                    Require all granted
            </Files>
    </Directory>

    ErrorLog        /home/vagrant/logs/error.log
    CustomLog       /home/vagrant/logs/access.log combined

    WSGIScriptAlias / /home/vagrant/photoapp.com/photoapp/wsgi.py


</VirtualHost>

但是每次我通过dev.photoapp.com访问该站点(hosts文件已被修改)时,都会收到错误500和上面的回溯消息。

注意

  1. 从python shell内import django工程
  2. `python manage.py runserver可以使用URL 127.0.0.1:8000正常加载
  3. sys.path输出:

    ['','/ usr / bin','/usr/local/lib/python2.7/dist-packages/django','/usr/lib/python2.7','/usr/lib/python2.7 /plat-x86_64-linux-gnu'、'/usr/lib/python2.7/lib-tk'、'/usr/lib/python2.7/lib-old'、'/usr/lib/python2.7/ lib-dynload','/ usr / local / lib / python2.7 / dist-packages','/ usr / lib / python2.7 / dist-packages','/ usr / lib / python2.7 / dist-packages / IPython的/扩展]

因此,我可以看到django软件包在路径上是可访问的。 但这不能解决Apache访问问题。

有任何想法吗?

尝试添加:

WSGIPythonPath /home/vagrant/photoapp.com

在您的virtualhost配置文件的顶部。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM