Create 'remember me' feature in default django login view

匿名 (未验证) 提交于 2019-12-03 01:41:02

问题:

I want to add remember me checkbox to my login view. I am using 'django.contrib.auth.views.login' view for login. I tried putting 'SESSION_COOKIE_AGE = 360' and a checkbox named "remember_me" after reading related questions. But, this didn't help. Seems like this feature isn't there in the default login view. Or am I missing something?

回答1:

Of course this is not in default login view. But you extend the default login form. Add this remember me feature in extended form, and then declare log in url like this:

url(r'^login/$',         auth_views.login,         {'template_name': 'your/login/template.html', 'form':YourExtendedForm},         name='auth_login'),

Also. There are many remember me snippets and projects out there. Do some googling and you will find working example in no time... like :https://github.com/jimfmunro/django-remember-me

Alan



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!