【发布时间】:2015-03-23 04:54:20
【问题描述】:
我正在为 django 项目配置的 vagrant box 中设置本地开发环境。因此,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 和上面的回溯消息。
注意
-
import django在 python shell 中工作 - `python manage.py runserver 使用 url 127.0.0.1:8000 加载正常
-
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/extensions']
所以我可以看到路径上可以访问 django 包。但它不能通过 Apache 访问来解决。
有什么想法吗?
【问题讨论】:
标签: python django apache mod-wsgi