Python apache无法使用django项目导入设置

Python apache无法使用django项目导入设置,python,django,apache,mod-wsgi,Python,Django,Apache,Mod Wsgi,我想将django与apache一起使用。我的目录树如下 /home/avlahop/development/django/rhombus2 ├── accounts │   ├── __init__.py │   ├── __init__.pyc │   ├── models.py │   ├── tests.py │   ├── urls.py │   ├── urls.pyc │   ├── views.py │   └── views.pyc ├── admin │   ├── css

我想将django与apache一起使用。我的目录树如下

/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)
My 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>
什么是。。。这里出了问题。我对另一个站点也有同样的问题,另一个virtualhost在不同的conf文件中,我得到了拒绝的权限。所以两个站点代码相同,错误不同。我在这里真的很沮丧。我不想使用php…php很容易部署…

如中所述,您应该指定python路径,如下所示:

WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com
作为替代方案,您可能希望将指令与python_path参数一起使用,这在中也有说明

在您的情况下/path/to/mysite.com应该是/home/avlahop/development/django/rhombs2


另外,请注意,将源代码放在DocumentRoot下被认为是一种不好的做法,因为1不需要运行站点,2在某些情况下允许攻击者访问源代码。如果我没有误解的话,只有静态文件应该位于DocumentRoot下。

但我有它。请看my site.conf的第一行。我应该在DocumentRoot中放什么?。仅模板和静态?这是否意味着我需要更改设置文件中的模板文件夹?我想是的。这不是很灵活。如果我有许多具有不同WSGIPythonPath的虚拟主机呢。我无法将它们放在一个配置中。对吗?请尝试在文件系统树上下移动WSGIPythonPath。模板也应该位于DocumentRoot之外。如果我没有弄错的话,Templates文件夹应该有相对路径,所以除非您指定了绝对路径,否则您不必更改它。如果您有许多虚拟主机,则应为每个虚拟主机配置mod_wsgi。此外,如果由于某些错误而无法导入设置文件,则会出现相同的错误。尝试切换到该virtualenv,运行交互式python控制台并导入您的设置文件-我尝试了一些错误…相同的错误…我可以在一个conf文件中设置多少WSGIPythonPath?我猜是一个。因此,为不同站点提供一个conf的唯一方法是将它们的wsgi.py文件放在一个目录中,与django代码分开。我不是在一个虚拟的、普通的python中。如果我运行./manage.py shell,我可以正常导入菱形设置。它可以在django的测试WebServer中工作,即使在简单的交互式python shell中,我也可以导入rhombus.settings/home/avlahop/development/django/rhombs2/mycal在PYTHONPATH中,我不知道为什么。
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com
WSGIDaemonProcess [other args] python-path=/path/to/mysite.com