python - 如何使用 django 配置 apache?

标签 python django apache

我正在尝试使用 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/

相关文章:

python - Flask Cookie 不起作用

python - Python 3 中的 Django 问题 "super() argument 1 must be type, not WSGIRequest"

apache - 无法启动 SpagoBI 服务器(多合一 spagobi 服务器)版本 5.2

python - 如何将给定的 Excel 文件转换为 Python 中的字典?

Python 单元测试 : Can we repeat Unit test case execution for a configurable number of times?

python - Django Queryset - 获取最后一个相关对象并按其数据过滤

php - CodeIgniter - 重定向子域设置为 "controllers"中的文件夹

apache - 更新 Apache SSL 证书

python - 如何在 Alpine Linux 容器上安装 pyzmq?

不同货币的 Django url 模式