django - 使用基本身份验证保护一些Web路径

w--*_*w-- 9 django mod-wsgi basic-authentication django-admin

我是django的新手,只是尝试了几个简单的实验来弄湿我的脚.我正在运行django 1.0,apache2 prefork和mod_wsgi.我正在尝试使用以下url结构构建一个站点

/
/members
/admin
Run Code Online (Sandbox Code Playgroud)

根基本上是一个公共区域.
应使用基本身份验证(可能由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>
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我指出正确的方向(或告诉我= 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>
Run Code Online (Sandbox Code Playgroud)

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

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

谢谢

Gra*_*ton 8

更改:

<Directory /django/rc/apache_httpauth>
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/django/_HTPASSWD/.htpasswd"
Require valid-user
</Directory>
Run Code Online (Sandbox Code Playgroud)

至:

<Location /members>
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/django/_HTPASSWD/.htpasswd"
Require valid-user
</Location>
Run Code Online (Sandbox Code Playgroud)

我不相信你应该需要:

WSGIScriptAlias /members /django/rc/apache_httpauth/django.wsgi
Run Code Online (Sandbox Code Playgroud)