本文整理汇总了Python中app.models.state.State.to_hash方法的典型用法代码示例。如果您正苦于以下问题:Python State.to_hash方法的具体用法?Python State.to_hash怎么用?Python State.to_hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.state.State
的用法示例。
在下文中一共展示了State.to_hash方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: states
# 需要导入模块: from app.models.state import State [as 别名]
# 或者: from app.models.state.State import to_hash [as 别名]
def states():
"""Handle GET and POST requests to /states route.
Return a list of all states in the database in the case of a GET request.
Create a new state in the database in the case of a POST request
"""
# handle GET requests:
# --------------------------------------------------------------------------
if request.method == 'GET':
list = ListStyle.list(State.select(), request)
return jsonify(list)
# handle POST requests:
# --------------------------------------------------------------------------
elif request.method == 'POST':
try:
record = State(name=request.form["name"])
record.save()
return jsonify(record.to_hash())
# return 409 state with given name already exists
except IntegrityError:
return json_response(
add_status_=False,
status_=409,
code=10001,
msg="State already exists"
)