使用 apache 和 mod_wsgi 时,我在哪里存储我的 django 项目代码?

Where do I store my django project code when using apache and mod_wsgi?

我正在查看 django 网站上似乎存在冲突的信息。

在这个页面上: https://docs.djangoproject.com/en/1.7/intro/tutorial01/

它说:

It’s not a good idea to put any of this Python code within your Web server’s document root, because it risks the possibility that people may be able to view your code over the Web. That’s not good for security.

Put your code in some directory outside of the document root, such as /home/mycode.

但是,在此页面上: https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/modwsgi/ 它说 Apache 应该这样设置:

WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com

<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

后者不是显示www根目录下的工程文件吗?

那么哪个是正确的?前者还是后者?

我使用了这些 linux 命令来设置项目:

cd /home/personal/network/django
django-admin.py startproject djnet

然后我将其放入 httpd.conf:

WSGIScriptAlias / /home/personal/network/django/djnet/wsgi.py
WSGIPythonPath /home/personal/network/django
<Directory /home/personal/network/django/djnet>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

这行得通,但我担心我引用的第一页中的 "That’s not good for security" 行。

是否应该将django-admin startproject生成的项目代码放在与Apache目录不同的目录中?如果是这样,我将如何配置 Apache?

不是,为什么说显示的是文档根目录下的文件呢?它没有,它在“/path/to/mysite.com”中显示它们。您所做的是正确的,并且不在网络根目录中。