# encoding=utf-8 from flask import Flask,make_response app = Flask(__name__) @app.route("/string/") def return_string(): return "Hello,world" @app.route("/object/") def return_object(): headers={‘Content-Type‘:‘text/plain‘} return make_response(‘Hello,world‘,200,headers) @app.route("/tuple/") def return_tuple(): return "hello,world",304,{‘Content-Type‘:‘text/plain‘}
# encoding=utf-8 from flask import Flask,request app = Flask(__name__) def dump_request_detail(request): request_detail=""" request.endpoint:{request.endpoint} request.method:{request.method} request.view_args:{request.view_args} request.args:{request.args} request.form:{request.form} request.user_agent:{request.user_agent} request.files:{request.files} request.is_xhr:{request.is_xhr} {request.headers}""".format(request=request).strip() return request_detail @app.before_request def call_me(): app.logger.debug(dump_request_detail(request)) @app.after_request def call_me(response): app.logger.debug("#After Request#\n"+repr(response)) return response @app.route("/string/") def return_string(): return "Hello,World"
本文出自 “专注linux” 博客,请务必保留此出处http://forlinux.blog.51cto.com/8001278/1420968
原文地址:http://forlinux.blog.51cto.com/8001278/1420968