简体   繁体   English

如何使用Django配置apache?

[英]how do you configure apache with django?

I am trying to configure django with apache. 我正在尝试用apache配置django。 I do see two different site-packages directory in my system: 我在系统中确实看到两个不同的site-packages目录:

 /usr/lib64/python2.6/site-packages
 /usr/local/lib64/python2.6/site-packages

The django and all the necessary libraries are installed in django和所有必需的库都安装在

/usr/local/lib64/python2.6/site-packages

How do I ensure apache reads the path as default python library? 如何确保apache将路径读取为默认python库?

You don't have to worry about that. 您不必为此担心。 Python will look for packages in both of those paths. Python将在这两个路径中寻找包。

From Python docs : Python文档

First, consider that many Linux distributions put Python in /usr , rather than the more traditional /usr/local . 首先,考虑到许多Linux发行版都将Python放在/usr ,而不是更传统的/usr/local This is entirely appropriate, since in those cases Python is part of "the system" rather than a local add-on. 这是完全适当的,因为在这种情况下,Python是“系统”的一部分,而不是本地附加组件。 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 . 但是,如果要从源代码安装Python模块,则可能希望它们放入/usr/local/lib/python2.X而不是/usr/lib/python2.X

You just need to configure the path to your django project's wsgi.py file. 您只需要配置django项目的wsgi.py文件的路径。 You can do it like this: 您可以这样做:

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>

Note that wherever I've written mysite/mysite it means your project's inner directory (which contains settings, wsgi, etc. files) 请注意,无论我在哪里写mysite/mysite ,都表示项目的内部目录(包含设置,wsgi等文件)。

EDIT 编辑

In case you want to see if those folders are in Python's search path , you can do this: 如果您想查看这些文件夹是否在Python的搜索路径中 ,可以执行以下操作:

>>> import sys
>>> sys.path
# outputs python search path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM