本文整理汇总了Python中forms.LoginForm.error_class方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.error_class方法的具体用法?Python LoginForm.error_class怎么用?Python LoginForm.error_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.LoginForm
的用法示例。
在下文中一共展示了LoginForm.error_class方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import error_class [as 别名]
def login(request):
if 'openid' in request.GET or request.method == 'POST':
form = LoginForm(request.REQUEST)
if form.is_valid():
client = _openid_consumer(request)
try:
auth_request = client.begin(form.cleaned_data['openid'])
if QUERY_EMAIL:
sreg = SRegRequest()
sreg.requestField(field_name=SRegField.EMAIL, required=True)
auth_request.addExtension(sreg)
ax = FetchRequest()
ax.add(AttrInfo(AXAttribute.CONTACT_EMAIL,
required=True))
auth_request.addExtension(ax)
callback_url = reverse(callback)
state = SocialLogin.marshall_state(request)
callback_url = callback_url + '?' + urlencode(dict(state=state))
redirect_url = auth_request.redirectURL(
request.build_absolute_uri('/'),
request.build_absolute_uri(callback_url))
return HttpResponseRedirect(redirect_url)
except DiscoveryFailure, e:
if request.method == 'POST':
form._errors["openid"] = form.error_class([e])
else:
return render_authentication_error(request)
示例2: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import error_class [as 别名]
def login(request):
context = {}
form = LoginForm(request.POST or None)
context['form'] = form
if request.method == 'POST' and form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
try:
next = request.GET['next']
except:
next = '/user/dashboard'
user = authenticate(username=username, password=password)
if user is not None:
login_auth(request, user)
return redirect(next)
else:
# 400
form.errors['__all__'] = form.error_class(["Login failure. Verify your user/password combination"])
return render_to_response('user/login.html', context, context_instance=RequestContext(request))