本文整理汇总了Python中model.User.to_json方法的典型用法代码示例。如果您正苦于以下问题:Python User.to_json方法的具体用法?Python User.to_json怎么用?Python User.to_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.to_json方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import to_json [as 别名]
def create_user():
email = request.json.get('email')
password = request.json.get('password')
org_name = request.json.get('org_name')
name = request.json.get('name')
image_url = request.json.get('image_url')
is_enabled = request.json.get('is_enabled')
org_id = None
if email is None or password is None:
abort(400) # missing arguments
if User.query.filter_by(email=email).first() is not None:
abort(400) # existing user
if org_name is not None:
org = Org.query.filter_by(name=org_name).first()
if org is not None:
org_id = org.id
user = User(
email=email,
password=password,
org_id=org_id if org_id is not None else None,
name=name,
image_url=image_url,
is_enabled=is_enabled,
)
db.session.add(user)
db.session.commit()
return jsonify(user.to_json())
示例2: get_users
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import to_json [as 别名]
def get_users():
user=User()
pageIndexParam = request.form['pageIndex']
sex=request.form['sex']
username=request.form['username']
query=User.query
###条件查询####
if sex:
query=query.filter(User.sex == sex)
if username:
query=query.filter(User.username == username)
pageIndexParam=int(pageIndexParam)+1
total=len(query.all())
paginate = query.paginate(pageIndexParam, 10, False)
users = paginate.items
userlist = []
for user in users:
userlist.append(user.to_json())
return (jsonify(rows=userlist,results=total))
示例3: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import to_json [as 别名]
def post(self):
user = User(**request.json)
user.save()
return json.loads(User.to_json(user))