本文整理汇总了Python中app.users.models.User.locale方法的典型用法代码示例。如果您正苦于以下问题:Python User.locale方法的具体用法?Python User.locale怎么用?Python User.locale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.users.models.User
的用法示例。
在下文中一共展示了User.locale方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import locale [as 别名]
def register():
form = RegisterForm(request.form)
if form.validate_on_submit():
existing_user = User.query.filter_by(email=form.email.data).first()
if existing_user:
form.email.errors = (_('This email is already taken'),)
elif not allow_password(form.password.data):
form.password.errors = (_(
'Your password must contain at least 8 '
'(printable) characters.'
),)
else:
user = User(
email=form.email.data,
password=generate_password_hash(form.password.data),
name=form.name.data,
)
user.set_geo_from_ip(request.remote_addr)
user.locale = request.accept_languages.best_match(
app.config['LANGUAGES']
)
db.session.add(user)
db.session.commit()
login_user(user, remember=True)
send_confirmation_email(user)
flash(_('An email has been sent to you with a confirmation link. '
'Please login to your email at your convenience '
'and click the link to finish registration.'))
return redirect(url_for('home'))
return render_template('users/register.html', form=form)