我想用apache使用django。我的目录树是以下
/home/avlahop/development/django/rhombus2
├── accounts
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ ├── urls.pyc
│ ├── views.py
│ └── views.pyc
├── admin
│ ├── css
│ ├── img
│ │ ├── gis
│ └── js
├── customer
│ ├── migrations
│ ├── models.py
│ ├── models.pyc
│ ├── views.py
│ └── views.pyc
├── __init__.py
├── __init__.pyc
├── manage.py
├── media
├── mycal
├── mypil
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ ├── urls.pyc
│ ├── views.py
│ └── views.pyc
├── rhombus
│ ├── api.py
│ ├── api.pyc
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── rhombus.db
│ ├── settings.py
│ ├── settings.pyc
│ ├── urls.py
│ ├── urls.pyc
│ ├── wsgi.py
│ └── wsgi.pyc
├── scripts
│ ├── create_data_files.py
│ ├── create_data_files.pyc
│ ├── find_server.py
│ ├── __init__.py
│ ├── __init__.pyc
│ └── populatedb.py
├── settings
├── static
├── tastypie
├── templates
wsgi.py
import os, sys
root = os.path.join(os.path.dirname(__file__),'..')
sys.path.insert(0, root)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rhombus.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
我的site.conf文件包含以下代码(并已启用)
WSGIPythonPath /home/avlahop/development/django/rhombus2
<VirtualHost *:80>
ServerAdmin webmast@rhombus.com
ServerName myrhombus.com
ServerAlias www.myrhombus.com
DocumentRoot /home/avlahop/development/django/rhombus2
WSGIScriptAlias / /home/avlahop/development/django/rhombus2/rhombus/wsgi.py
<Directory /home/avlahop/development/django/rhombus2/rhombus>
<Files wsgi.py>
Require all granted
</Files>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
/ home / avlahop / development / django / rhombus2(包括root)下的所有内容都被编译为755,这是其他人的rx。但是我收到以下错误
ImportError: Could not import settings 'rhombus.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named rhombus.settings
这里出了什么问题。我和另一个站点(另一个虚拟主机在不同的conf文件中)有相同的东西,我得到了权限被拒绝。我复制粘贴了上面的代码,并更改了路径。所以2个站点的代码相同,错误不同。我真的很沮丧。我不想去PHP ...... Php很容易部署......
答案 0 :(得分:0)
如Django documentation中所述,您应该指定python路径如下:
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com
作为替代方案,您可能希望将WSGIDaemonProcess
指令与python_path argument
一起使用(这也在Django docs中说明)
WSGIDaemonProcess [other args] python-path=/path/to/mysite.com
在您的情况下,/path/to/mysite.com
应为/home/avlahop/development/django/rhombus2
另外,请注意,将源代码放在DocumentRoot下是一种不好的做法,因为它(1)不需要运行站点,(2)在某些情况下允许攻击者访问源代码。如果我没有误会,只有静态文件应位于DocumentRoot下。