【发布时间】:2009-09-03 06:38:41
【问题描述】:
我对 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,但它有效..
有没有更好的方法来做我想做的事?
这样做有什么缺点吗?
谢谢
【问题讨论】:
标签: django django-admin mod-wsgi basic-authentication