方法或属性 | 描述 |
---|
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) | 设置cookie |
from flask import Flask, json, make_response
app = Flask(__name__)
@app.route('/1')
def hello1():
return 'Hello'
@app.route('/2')
def hello11():
test={'key1':'value1','key2':'value2'}
return json.dumps(test)
@app.route('/3')
def hello2():
return 'Hello3',200,{"key":"value"}
@app.route('/4')
def hello3():
rsp = make_response('hello4')
rsp.mimetype = 'text/plain'
rsp.headers['key'] = 'value'
rsp.set_cookie('user','wang')
return rsp
if __name__ == '__main__':
app.run(debug=True)