本文整理汇总了Python中database.User.view方法的典型用法代码示例。如果您正苦于以下问题:Python User.view方法的具体用法?Python User.view怎么用?Python User.view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.User
的用法示例。
在下文中一共展示了User.view方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sign_up
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import view [as 别名]
def sign_up():
errors = []
form = SignUpForm(request.form)
if request.method == 'POST' and form.validate():
# looks like everything ok, check db
username = form.username.data
password = form.password.data
user = list(User.view('users/by_username', key=username))
if user:
errors.append('User already exists')
else:
new_user = make_user_from_request(request)
g.db.save_doc(new_user)
flash('You have successfully registered')
return redirect(url_for('show_posts'))
elif request.method == 'POST' and not form.validate():
errors.extend(format_form_errors(form.errors.items()))
return render_template('sign_up.html', form = form, errors = errors)
示例2: login
# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import view [as 别名]
def login():
errors = []
form = LoginForm(request.form)
if request.method == 'POST' and form.validate():
username = form.username.data
password = form.password.data
user = list(User.view('users/by_username', key=username))
if not user:
errors.append('Invalid username')
elif make_password_hash(user[0].salt, password) != user[0].password:
errors.append('Invalid password')
else:
session['logged_in'] = True
session['uid'] = user[0]._id
session['privileged'] = user[0].privileged
flash('You were logged in')
return redirect(url_for('show_posts'))
elif request.method == 'POST' and not form.validate():
errors.extend(format_form_errors(form.errors.items()))
return render_template('login.html', form = form, errors = errors)