[컴][파이썬] flask 에서 RESTful API 를 위한 argument checking

flask 에서 argument 를 체크 하는 방법 / argument 검사 /


Argument checking

from flask_restful import reqparse
...

@app.route('/report/content-rank/', methods=['POST', 'GET'])
def content_rank():

    # :see: http://flask-restful.readthedocs.org/en/latest/reqparse.html
    parser = reqparse.RequestParser()
    parser.add_argument('domain_seq', type=int, required=True, location='args',
                        help="domain_seq cannot be blank!")
    parser.add_argument('path_id', type=int, required=True, location='args',
                        help="path_id cannot be blank!")
    parser.add_argument('from', type=str, required=True, location='args',
                        help="from cannot be blank!")
    parser.add_argument('to', type=str, required=True, location='args',
                        help="to cannot be blank!")


    args = parser.parse_args()
    ...


Response

from flask import make_response
...
@app.route('/muchart/rss/<chart_id>', methods=['POST', 'GET'])
def chart_rss(chart_id):
    chartdataString = muchart.makeChartDataFromAPage(request, chart_id)
    response = make_response(chartdataString)

    return response



See Also


  1. Caching — Flask Documentation (0.10)



Reference

  1. Request Parsing — Flask-RESTful 0.2.1 documentation

댓글 없음:

댓글 쓰기