2

I've been investigating methods of locking down an entire page. A colleague drew my attention to django-lockdown. I've installed and and my code looks like this:

INSTALLED_APPS += ('lockdown',)
MIDDLEWARE_CLASSES += ('lockdown.middleware.LockdownMiddleware',)
LOCKDOWN_PASSWORD = 'letmein'

I'm using the supplied template code that comes with bit bucket that looks like this:

{% extends "lockdown/base.html" %}

{% block title %}Coming soon...{% endblock %}

{% block content %}
<div id="lockdown">
  <h2>Coming soon...</h2>

  <p>This is not yet available to the public.</p>

  {% if form %}

  <form action="" method="post">
    {{ form.as_p }}
    <p><input type="submit" value="Preview"></p>
  </form>

  {% endif %}

</div>
{% endblock %}

When I run a server locally I get no errors however the form itself does not appear on the screen. There is no place to type in a password which leads me to believe {% if form %} probably isn't true.

There isn't a lot of documentation available online so I'm struggling to fix this error.

4

2 回答 2

3

您的锁定密码应该是一个元组。类似于 LOCKDOWN_PASSWORDS = ('letmein', 'beta')。

此外,您不应该编写模板来使其正常工作。Django-lockdown 包含电池。开箱即用(只有这个):

  • pip install django-lockdown,
  • 将 'lockdown', (带有尾随逗号)添加到 APPS,
  • 添加 'lockdown.middleware.LockdownMiddleware', (带有尾随逗号)到中间件,
  • 添加 LOCKDOWN_PASSWORDS = ('letmein', 'beta')

[设置中的所有这些东西]

于 2013-07-29T10:30:48.493 回答
0

从文档中引用:

要使用密码启用锁定站点或视图的管理员预览,请将 LOCKDOWN_PASSWORDS 设置设置为一个或多个纯文本密码的元组。

所以你应该有这个设置:

LOCKDOWN_PASSWORDS = ('let me in', )
于 2013-07-29T10:31:26.280 回答