我怎样才能重新使用原来的管理员登录()和AuthenticationForm设置较长的Cookie有效期与"记住我"选项,在登录页面检查用户?我目前正在通过urls.py使用内置登录
url(r'^login/$','django.contrib.auth.views.login', {'template_name': 'authentication/login.html'}, name='login'),
Run Code Online (Sandbox Code Playgroud)
该复选框在我的login.html中实现为:
<label><input name="remember_me" type="checkbox">Keep me logged in</label>
Run Code Online (Sandbox Code Playgroud)
但我不知道如何通过AuthenticationForm传递信息给django.contrib.auth.views.login
目前,如果用户未选中"记住我"框,则会在settings.py中定义cookie年龄
SESSION_COOKIE_AGE = 360
Run Code Online (Sandbox Code Playgroud)
我发现了几个类似的问题,但我认为这不需要安装单独的应用程序.下面的代码片段(http://djangosnippets.org/snippets/1881/)看起来很有希望,但我只编写了几个月的python和Django,但是我无法让它工作:
def login(request, *args, **kwargs):
if request.method == 'POST':
if not request.POST.get('remember_me', None):
request.session.set_expiry(0)
return auth_views.login(request, *args, **kwargs)
Run Code Online (Sandbox Code Playgroud)