本文整理汇总了Python中forms.LoginForm.errors['password']方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.errors['password']方法的具体用法?Python LoginForm.errors['password']怎么用?Python LoginForm.errors['password']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.LoginForm
的用法示例。
在下文中一共展示了LoginForm.errors['password']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import errors['password'] [as 别名]
def user_login(request):
if not request.user.is_anonymous():
return HttpResponseRedirect('/')
if request.method == "POST":
form = LoginForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
username = cd['username']
password = cd['password']
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
if "next" in request.REQUEST:
return HttpResponseRedirect(request.REQUEST["next"])
else:
return HttpResponseRedirect("/")
else:
form.errors['password'] = u"帐号验证失败!"
context = RequestContext(request, {
'form': form })
return render_to_response("login.html", context)
else:
context = RequestContext(request, {
'form': form })
return render_to_response("login.html", context)
else:
form = LoginForm()
context = RequestContext(request, {
'form': form })
return render_to_response("login.html", context)
示例2: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import errors['password'] [as 别名]
def login():
form = LoginForm(request.form)
#_on_submit():
if form.validate():
username = form.username.data
password = form.password.data
cur = g.db.execute('select username from users where username = ? and password = ?', [username, password])
user = cur.fetchall()
if user is not None:
session['logged_in'] = True
flash('You were logged in')
return redirect(url_for('show_entries'))
else:
form.errors['username'] = ['Incorrect username or password']
form.errors['password'] = ['Incorrect username or password']
return render_template('login.html', form=form)