flask response 객체

2860 단어 flask
메서드 또는 속성
묘사
headers
status
status_code
data
get_json(force=False, silent=False, cache=True)
is_json
max_cookie_size
mimetype
set_cookie(key, value=”, max_age=None, expires=None, path=’/’, domain=None, secure=False, httponly=False, samesite=None)
쿠키 설정
from flask import Flask, json, make_response
app = Flask(__name__)

@app.route('/1')
def hello1():
    return 'Hello'# , 200, MIME  text/html response 

@app.route('/2')
def hello11():
    test={'key1':'value1','key2':'value2'}
    return json.dumps(test)# json 

@app.route('/3')
def hello2():
    return 'Hello3',200,{"key":"value"}# , ,MIME  text/html response , headers

@app.route('/4')
def hello3():
 rsp = make_response('hello4') # response 
 rsp.mimetype = 'text/plain'
 rsp.headers['key'] = 'value'
 rsp.set_cookie('user','wang')# request.cookies 
 return rsp # make_response response

if __name__ == '__main__':
    app.run(debug=True)

참조 자료:http://www.jianshu.com/p/0ced03604e24

좋은 웹페이지 즐겨찾기