9

我对 django 还很陌生,只是尝试了几个简单的实验来弄湿我的脚。我正在运行 django 1.0、apache2 prefork 和 mod_wsgi。我正在尝试使用以下 url 结构构建网站

/
/members
/admin

根基本上是一个公共区域。
成员路径应使用基本身份验证(可能由 apache 进行身份验证)
进行保护,管理路径应使用内置的 django 身份验证进行保护。

按照文档中的示例,我基本上可以使用基本身份验证保护整个站点,但这不是我想要的。

除了来自虚拟主机配置:

WSGIScriptAlias / /django/rc/apache/django.wsgi
<Directory /django/rc/apache>
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/django/_HTPASSWD/.htpasswd"
Require valid-user

# Order allow,deny
# Allow from all
</Directory>

谁能帮我指出正确的方向(或直接告诉我=P)如何使这成为可能?

谢谢


编辑:玩了一会儿后,我发现我可以做类似的事情:

WSGIScriptAlias / /django/rc/apache/django.wsgi
<Directory /django/rc/apache>
Order allow,deny
Allow from all
</Directory>

WSGIScriptAlias /members /django/rc/apache_httpauth/django.wsgi
<Directory /django/rc/apache_httpauth>
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/django/_HTPASSWD/.htpasswd"
Require valid-user

</Directory>

django.wsgi 文件基本上是复制到另一个目录的同一个文件,因此 WSGIScriptAlias 是不同的。这是hack-ish,但它有效..

有没有更好的方法来做我想做的事?
这样做有什么缺点吗?

谢谢

4

1 回答 1

8

改变:

<Directory /django/rc/apache_httpauth>
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/django/_HTPASSWD/.htpasswd"
Require valid-user
</Directory>

至:

<Location /members>
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/django/_HTPASSWD/.htpasswd"
Require valid-user
</Location>

我不相信你应该需要:

WSGIScriptAlias /members /django/rc/apache_httpauth/django.wsgi
于 2009-09-03T07:08:16.263 回答