state.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:airbnb_clone 作者: bennettbuchanan 项目源码 文件源码
def handle_state_id(state_id):
    '''Select the state with the id from the database and store as the variable
    `state` with a GET request method. Update the data of the particular state
    with a PUT request method. This will take the parameters passed and update
    only those values. Remove the state with this id from the database with
    a DELETE request method.

    Keyword arguments:
    state_id: The id of the state from the database.
    '''
    try:
        state = State.select().where(State.id == state_id).get()
    except State.DoesNotExist:
        return jsonify(msg="There is no state with this id."), 404

    if request.method == 'GET':
        return jsonify(state.to_dict()), 200

    elif request.method == 'DELETE':
        try:
            state = State.delete().where(State.id == state_id)
        except State.DoesNotExist:
            raise Exception("There is no state with this id.")
        state.execute()
        return jsonify(msg="State deleted successfully."), 200
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号