本文整理汇总了Python中models.User.find_by方法的典型用法代码示例。如果您正苦于以下问题:Python User.find_by方法的具体用法?Python User.find_by怎么用?Python User.find_by使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.find_by方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: api_get_users
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by [as 别名]
def api_get_users():
total = User.count_all()
page = Page(total, _get_page_index())
users = User.find_by("order by created_at desc limit ?,?", page.offset, page.limit)
for u in users:
u.password = "******"
return dict(users=users, page=page)
示例2: api_get_users
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by [as 别名]
def api_get_users():
total = User.count_all()
page = Page(total, _get_page_index())
users = User.find_by('order by created_at desc limit ?,?', page.offset, page.limit)
for u in users:
# replace password with '******'
u.password = '******'
return dict(users=users, page=page)
示例3: route_weibo_index
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by [as 别名]
def route_weibo_index(request):
headers = {
'Content-Type': 'text/html',
}
header = response_with_header(headers)
user_id = request.query.get('user_id', -1)
user_id = int(user_id)
user = User.find(user_id)
if user is None:
return error(request)
# 找到 user 发布的所有 weibo
weibos = Weibo.find_all(user_id=user.id)
# 任一 user 访问任一 index
current_username = current_user(request)
u = User.find_by(username=current_username)
if u is None:
return redirect('/login')
def weibo_tag(weibo):
comment_list = Comment.find_all(weibo_id=weibo.id)
comments = '<br>'.join([c.content for c in comment_list])
# format 函数的字典用法
# 注意 u.id 是 current_user
# user.username 是博主
w = {
'id': weibo.id,
'user_id': u.id,
'content': weibo.content,
'username': user.username,
'time': weibo.created_time,
'comments': comments,
}
# 手动处理 weibos 这个 list
# 把每个 weibo 以 <p> 的形式展现在页面
return """
<p>{content} from {username}@{time}
<a href="/weibo/delete?id={id}">删除</a>
<a href="/weibo/edit?id={id}">修改</a></p>
<button class="weibo-show-comment" data-id="{id}">评论</button>
<div>
{comments}
</div>
<div id="id-div-comment-{id}" class="weibo-comment-form weibo-hide">
<form action="/weibo/comment/add" method="post">
<input name="user_id" value="{user_id}" type="hidden">
<input name="weibo_id" value="{id}" type="hidden">
<textarea name="content"></textarea>
<button type="submit">添加评论</button>
</form>
</div>
</p>
""".format(**w)
# 用 join() 返回 str
weibos = '\n'.join([weibo_tag(w) for w in weibos])
body = template('weibo_index.html', weibos=weibos)
r = header + '\r\n' + body
return r.encode(encoding='utf-8')
示例4: api_get_users
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by [as 别名]
def api_get_users():
cwd = os.getcwd()
total = User.count_all()
page = Page(total, _get_page_index())
users = User.find_by('order by created_at desc limit ?,?', page.offset, page.limit)
logging.info(str(users))
for u in users:
u.password = '******'
return dict(users=users, page=page,cwd=image_path)
示例5: api_get_users
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by [as 别名]
def api_get_users():
users = User.find_by('order by created_at desc')
for u in users:
u.password = '******'
return dict(users=users)
# @view('blogs.html')
# @get('/')
# def index():
# blogs = Blog.find_all()
# return dict(blogs=blogs, user=ctx.request.user)
示例6: route_weibo_update
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by [as 别名]
def route_weibo_update(request):
username = current_user(request)
user = User.find_by(username=username)
form = request.form()
content = form.get('content', '')
weibo_id = int(form.get('id', -1))
w = Weibo.find(weibo_id)
if user.id != w.user_id:
return error(request)
w.content = content
w.save()
return redirect('/weibo?user_id={}'.format(user.id))
示例7: api_get_users
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by [as 别名]
def api_get_users():
total = User.count_all()
page = Page(total, _get_page_index())
users = User.find_by('order by created_at desc limit ?,?', page.offset, page.limit)
for u in users:
u.password = '******'
return dict(users=users, page=page)
# @view('test_users.html')
# @get('/')
# def test_user():
# users = User.find_all()
# return dict(users=users)
示例8: route_weibo_delete
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by [as 别名]
def route_weibo_delete(request):
# headers = {
# 'Content-Type': 'text/html',
# }
username = current_user(request)
# header = response_with_header(headers)
user = User.find_by(username=username)
# 删除微博
weibo_id = request.query.get('id', None)
weibo_id = int(weibo_id)
w = Weibo.find(weibo_id)
w.delete()
return redirect('/weibo?user_id={}'.format(user.id))
示例9: route_weibo_add
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by [as 别名]
def route_weibo_add(request):
"""
这个函数相当于一个裸的 API
它提取某个 HTML页面 的数据
处理过后 redirect 到一个页面
"""
# headers = {
# 'Content-Type': 'text/html',
# }
username = current_user(request)
log('发微博的用户: ', username)
# header = response_with_header(headers)
user = User.find_by(username=username)
# 创建一个新微博实例
# 就是把 weibo_new.html 的数据处理
form = request.form()
w = Weibo(form)
w.user_id = user.id
w.save()
return redirect('/weibo?user_id={}'.format(user.id))
示例10: api_get_users
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by [as 别名]
def api_get_users():
users = User.find_by('order by create_at desc')
for u in users:
u.password = '******'
return dict(users=users)
示例11: User
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by [as 别名]
from models import User, Blog, Comment
import logging
from transwarp import db
logging.basicConfig(level = logging.DEBUG)
db.create_engine(user = 'root', password = 'password', database = 'myblog')
u = User(name='Test', email='[email protected]', password='1234567890', image='about:blank')
u.insert()
print 'new user id:', u.id
print 'create time:', u.created_at
u1 = User.find_first('where email=?', '[email protected]')
print 'find user\'s name:', u1.name
u1.delete()
u2 = User.find_by('where email=?', '[email protected]')
print 'find user:', u2
示例12: test_users
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by [as 别名]
def test_users():
users = User.find_by('order by created_at desc')
# hide the password
for u in users:
u.password = '******'
return dict(users=users)
示例13: api_get_users
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_by [as 别名]
def api_get_users():
users = User.find_by("order by created_at desc")
for u in users:
u.password = "******"
return dict(users=users)