本文整理汇总了Python中model.user.User.get_by_username方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_username方法的具体用法?Python User.get_by_username怎么用?Python User.get_by_username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.user.User
的用法示例。
在下文中一共展示了User.get_by_username方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import get_by_username [as 别名]
def post(self):
username = self.get_argument('username', '')
email = self.get_argument('email', '')
password = self.get_argument('password', '')
if not username or len(username) > 15:
self.render('home/register.html', error=111, username=username, email=email)
return
match = re.search(r'[\w.-][email protected][\w.-]+', email)
if not match:
self.render('home/register.html', error=113, username=username, email=email)
return
if not password:
self.render('home/register.html', error=110, username=username, email=email)
return
user = User.get_by_username(username)
if user:
self.render('home/register.html', error=112, username=username, email=email)
return
user = User.get_by_email(email)
if user:
self.render('home/register.html', error=114, username=username, email=email)
return
#走代理获取ip方式
reg_ip = self.request.headers['X-Real-Ip']
user = User.new(username, email, password, reg_ip)
if user:
self.set_secure_cookie('user_id', str(user.user_id), expires_days=30)
self.redirect(self.get_argument('next', '/'))
else:
self.render('home/register.html', error=115)
示例2: get
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import get_by_username [as 别名]
def get(self, username):
user = User.get_by_username(username)
if user:
page = self.get_argument('p', '1')
count, query = Topic.get_list_by_user(user)
pagination_ret = pagination(count, query, config.TOPIC_PAGE_SIZE, page)
self.render('user/user_page.html', user=user, tab={'user_topic_page': 'active'}, count=count,
avatar_html=avatar_generate(username, user.avatar_color, 167),
pagination=pagination_ret, page_url=self.request.path)
else:
self.write_error(404)