Django锁定认证 - 登录表单不工作 [英] Django lockdown authentication - Login form not working

查看:99
本文介绍了Django锁定认证 - 登录表单不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在调查锁定整个页面的方法。一位同事提请我注意 django-lockdown 。我已经安装并且我的代码如下所示:

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

我正在使用随机提供的模板代码,如下所示:

  {%extendslockdown / base html%} 

{%block title%}即将推出... {%endblock%}

{%block content%}
< div id = 锁定 >
< h2>即将推出...< / h2>

< p>这尚未向公众公开。< / p>

{%if form%}

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

{%endif%}

< / div>
{%endblock%}

当我在本地运行服务器时,我没有错误,表单本身不会出现在屏幕上。没有地方输入密码,导致我相信{%if form%}可能不是真的。



没有很多在线文档可用,所以我很难解决这个错误。

解决方案

您的锁定密码应为元组。像LOCKDOWN_PASSWORDS =('letmein','beta')的东西。



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




  • pip install django-lockdown,


  • 添加'lockdown.middleware.LockdownMiddleware'(带有逗号)到中间件,

  • 添加LOCKDOWN_PASSWORDS =('letmein','beta')



[所有这些设置]

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.

解决方案

Your lockdown password should be a tuple. Something like LOCKDOWN_PASSWORDS = ('letmein', 'beta').

Also you should not be writing a template to get it working. Django-lockdown is batteries included. Just out of the box (this and only this):

  • pip install django-lockdown,
  • add 'lockdown', (with trailing comma) to APPS,
  • add 'lockdown.middleware.LockdownMiddleware', (with trailing comma) to the middleware,
  • add LOCKDOWN_PASSWORDS = ('letmein', 'beta')

[all these things in settings]

这篇关于Django锁定认证 - 登录表单不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆