我正在尝试使用 apache 配置 django。我确实在我的系统中看到了两个不同的站点包目录:
/usr/lib64/python2.6/site-packages
/usr/local/lib64/python2.6/site-packages
django 和所有必需的库都安装在
/usr/local/lib64/python2.6/site-packages
如何确保 apache 将路径读取为默认 python 库?
最佳答案
你不必担心这个。 Python 将在这两个路径中查找包。
来自Python docs :
First, consider that many Linux distributions put Python in
/usr
, rather than the more traditional/usr/local
. This is entirely appropriate, since in those cases Python is part of "the system" rather than a local add-on. However, if you are installing Python modules from source, you probably want them to go in/usr/local/lib/python2.X
rather than/usr/lib/python2.X
.
您只需配置 django 项目的 wsgi.py
文件的路径。你可以这样做:
WSGIScriptAlias / /path/to/mysite/mysite/wsgi.py
WSGIPythonPath /path/to/mysite
<Directory /path/to/mysite/mysite>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
请注意,无论我在哪里编写mysite/mysite
,它都表示您项目的内部目录(其中包含设置、wsgi 等文件)
编辑
如果您想查看这些文件夹是否在 Python 的搜索路径中,您可以执行以下操作:
>>> import sys
>>> sys.path
# outputs python search path
关于python - 如何使用 django 配置 apache?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32185566/