我正在学习django,我正在尝试在apache下部署我的第一个基本django。
到目前为止我做了什么: 在根下:
installed python3.4
pip3.4 install virtualenvwrapper
用户" Cheng":
added to .bashrc:
VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.4
source /usr/local/bin/virtualenvwrapper.sh
mkvirtulenv ifthq
在root下
pip3.4 install django
"(ifthq)cheng"
navigate to /var/www
django-admin.py startproject ifthq
cd ifthq
python manage.py runserver <--works no problem
然后是有趣的部分,将项目附加到apache:
在root下,我在/ etc / httpd /的conf.d目录中设置了ifthq.conf。 ifthq.conf里面是:
WSGIPythonPath /var/www/ifthq:/home/cheng/.virtualenvs/ifthq/lib/python3.4/site-packages/
<VirtualHost *:80>
ServerName www.ifthq.com
ServerAlias ifthq.com
ServerAdmin cheng@trekfederation.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
# Alias /robots.txt /www/STORE/coffestatic/robots.txt
# Alias /favicon.ico /www/STORE/coffeestatic/favicon.ico
Alias /static/ /var/www/ifthq/static/
<Directory /var/www/ifthq/>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /var/www/ifthq/ifthq/wsgi.py
ErrorLog /var/log/httpd/error.log
LogLevel warn
CustomLog /var/log/httpd/access.log combined
</VirtualHost>
当我启动apache时,我得到了臭名昭着的500(内部服务器错误)。经过进一步审核,我从error.log获得此响应:
[Sun Oct 18 18:34:55.944407 2015] [:error] [pid 19250] [client 144.76.29.66:56465] ImportError: No module named django.core.wsgi
正如您所看到的,我正试图让apache为该页面提供服务。 wgsi.py位置是正确的。站点包位置是正确的。我觉得我在这里错过了一些愚蠢的东西。在virtualenv之外的root中,我做了pip3.4 install django
无济于事。
我还缺少什么? 感谢
更新1 这是我的wsgi.py更新,仍然没有去:
"""
WSGI config for ifthq project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""
import os, sys
# add the hellodjango project path into the sys.path
sys.path.append('/var/www/ifthq')
# add the virtualenv site-packages path to the sys.path
sys.path.append('/home/cheng/.virtualenvs/ifthq/lib/python3.4/site-packages')
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ifthq.settings")
application = get_wsgi_application()
答案 0 :(得分:1)
你试过这个吗? ImportError: No module named django.core.wsgi Apache + VirtualEnv + AWS + WSGI我认为你的wsgi.py代码存在问题。
编辑:
我可以在Centos VPS中向您展示适合我的配置:
在httpd.conf中
WSGIPythonPath /path/to/project/folder
<VirtualHost YourServerIp:80>
#WSGI conf
ServerName mysite.co
ServerAlias www.mysite.co
WSGIScriptAlias / /path/to/your/project/main/wsgi.py
Alias /robots.txt /path/to/your/robots.txt/folder
Alias /media/ /path/to/your/project/media/folder/
Alias /static/ /path/to/your/project/static/folder/
<Directory /path/to/your/project/static/folder/>
Order deny,allow
Allow from all
</Directory>
<Directory /path/to/your/project/media/folder/>
Order deny,allow
Allow from all
</Directory>
<Directory /path/to/your/project/wsgi.py/folder/>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
在我的wsgi.py
中 """
WSGI config for project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MainFolder.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
答案 1 :(得分:0)
我找到了答案。 使用另一个stackoverflow,我试图再次重新定位....我发现我的mod_wsgi是在YUM下安装时在默认python下设置的。
所以这就是我所做的: 我从源代码下载了新的mod_wsgi,将其解压缩,然后进入该文件夹。然后我运行了以下内容:
sudo ./configure --with-python=/usr/local/bin/python3.4
sudo make
sudo make install
这会将mod_wsgi重置为正确的python,并从那里完全落实到位。