我的目标是实施一些解决方案来限制大型 django 站点的登录尝试。这是当我尝试使用正确/不正确的凭据登录时返回的模板错误。我正在使用 django-rate-limit 模块:
http://django-ratelimit-backend.readthedocs.org/en/latest/usage.html。
<!-- BEGIN LOGIN FORM -->
<form class="login-form" {% url 'ratelimitbackend.views.login' %} method="post">{% csrf_token %}
<h3 class="form-title">Sign in to your account!</h3>
<div class="alert alert-danger display-hide">
<button class="close" data-close="alert"></button>
<span>
Sorry. You're username and/or password is invalid. Please try again.
</span>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Username</label>
<div class="input-icon">
<i class="fa fa-user"></i>
<input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Username" name="username"/>
</div>
</div>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Password</label>
<div class="input-icon">
<i class="fa fa-lock"></i>
<input class="form-control placeholder-no-fix" type="password" autocomplete="off" placeholder="Password" name="password"/>
</div>
</div>
<div class="form-actions">
<label class="checkbox">
<input type="checkbox" name="remember" value="1"/> Remember me </label>
<button type="submit" class="btn propagreen pull-right">
Login <i class="m-icon-swapright m-icon-white"></i>
</button>
</div>
<!-- <div class="login-options">
<h4>Or login with</h4>
<ul class="social-icons">
<li>
<a class="facebook" data-original-title="facebook" href="#">
</a>
</li>
<li>
<a class="twitter" data-original-title="Twitter" href="#">
</a>
</li>
<li>
<a class="googleplus" data-original-title="Goole Plus" href="#">
</a>
</li>
<li>
<a class="linkedin" data-original-title="Linkedin" href="#">
</a>
</li>
</ul>
</div> -->
<div class="forget-password">
<h4>Forgot your password ?</h4>
<p>
No worries! Click
<a href="../../user/password/reset" id="forget-password">
here
</a>
to reset your password.
</p>
</div>
</form>
<!-- END LOGIN FORM -->
我在 settings.py 中包含了 rate-limit 所需的中间件
('ratelimitbackend.middleware.RateLimitMiddleware',)
我将 urls.py 配置为这样
from ratelimitbackend import admin admin.autodiscover()