本文整理汇总了Python中forms.LoginForm.errors['username']方法的典型用法代码示例。如果您正苦于以下问题:Python LoginForm.errors['username']方法的具体用法?Python LoginForm.errors['username']怎么用?Python LoginForm.errors['username']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.LoginForm
的用法示例。
在下文中一共展示了LoginForm.errors['username']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import errors['username'] [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)
示例2: login_view
# 需要导入模块: from forms import LoginForm [as 别名]
# 或者: from forms.LoginForm import errors['username'] [as 别名]
def login_view(request, next_page=None):
tpl_vars = {'header': 'page', 'logged': False, 'signupform': SignupForm()}
if request.method == 'POST':
loginform = LoginForm(request.POST)
tpl_vars['loginform'] = loginform
if loginform.is_valid():
cd = loginform.cleaned_data
username, password = cd['username'], cd['password']
user = UserProfile.find(username)
if user:
if user.check_password(password):
user.backend = 'mongoengine.django.auth.MongoEngineBackend'
login(request, user)
if next_page:
return redirect(next_page)
return redirect('/')
loginform.errors['username'] = ['invalid username/password']
return render_to_response('twtapp/login.html',
RequestContext(request, tpl_vars))
# Invalid form data
return render_to_response('twtapp/login.html',
RequestContext(request, tpl_vars))
# We don't have a POST(so, it's most probably, a GET!)
if request.GET.get('next', None):
tpl_vars['hidden_next'] = request.GET['next']
tpl_vars['loginform'] = LoginForm()
return render_to_response('twtapp/login.html',
RequestContext(request, tpl_vars))