flask獲取真實iphtml
if request.headers.getlist("X-Forwarded-For"): ip = request.headers.getlist("X-Forwarded-For")[0]else: ip = request.remote_addr
2. flask reponse 添加header 信息:python
@app.after_requestdef after_request(response): response.headers.add('Access-Control-Allow-Origin', '*') return response
注意: 這種方法會在每一個response中都添加。flask
def index(): response = make_response(render_template('index.html', foo=42)) response.headers['X-Parachutes'] = 'parachutes are cool' return response
注意: 這種方法只會在單個的response中添加app
3. 直接傳輸文件ide
@app.route('/pic/<path:filename>')def send_pic(filename): return send_from_directory('/path/to/static/files', filename)