本文整理汇总了Python中django.contrib.auth.forms.AuthenticationForm.id方法的典型用法代码示例。如果您正苦于以下问题:Python AuthenticationForm.id方法的具体用法?Python AuthenticationForm.id怎么用?Python AuthenticationForm.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.forms.AuthenticationForm
的用法示例。
在下文中一共展示了AuthenticationForm.id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_or_logout_form
# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import id [as 别名]
def login_or_logout_form(context, next):
"""
Usage: {% login_or_logout_form next %}
After: Depending on whether the browsing user is logged in or not a login or logout
form has been displayed
After a successful login the user is redirected to the url next
"""
user = context['user']
request = context['request']
login_url = reverse('login')
if request.path == login_url:
return {'on_login_page': True }
if next == login_url:
next = reverse('index')
if not user.is_authenticated():
form = AuthenticationForm(auto_id = "login-form-%s")
form.fields['username'].widget.attrs['tabindex'] = 1
form.fields['password'].widget.attrs['tabindex'] = 2
form.id = "login-form"
return {'login' : True, 'form' : form , 'next': next}
else:
return {'login': False }