本文整理匯總了Python中app.models.city.City.state方法的典型用法代碼示例。如果您正苦於以下問題:Python City.state方法的具體用法?Python City.state怎麽用?Python City.state使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app.models.city.City
的用法示例。
在下文中一共展示了City.state方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_city
# 需要導入模塊: from app.models.city import City [as 別名]
# 或者: from app.models.city.City import state [as 別名]
def create_city(state_id):
"""
Create an city
Creates an city based on post parameters.
---
tags:
- city
parameters:
- name: name
in: query
type: string
description: name of the city to create
responses:
200:
description: Success message
schema:
id: success_message
properties:
status:
type: number
description: status code
default: 200
msg:
type: string
description: Status message
default: 'Success'
400:
description: Error message
schema:
id: error_message
properties:
status:
type: number
description: status code
default: 40000
msg:
type: string
description: Status message
default: 'Missing parameters'
"""
content = request.get_json(force=True)
if not all(param in content.keys() for param in ["name"]):
#ERROR
return error_msg(400, 40000, "Missing parameters")
try:
city = City()
city.name = content["name"]
city.state = state_id
city.save()
except Exception as e:
return error_msg(400, 400, "Error")
return error_msg(200, 200, "Success")