如何在Flask中的decorator函数中获取发送请求的客户机的IP地址和端口?在
from flask import Flask, request, jsonify
from functools import wraps
app = Flask(__name__)
def check_auth(f):
@wraps(f)
def decorated_function(*args, **kwargs):
print(request)
### Here I need the IP address and port of the client
return f(*args, **kwargs)
return decorated_function
@app.route('/test', methods=['POST'])
@check_auth
def hello():
json = request.json
json['nm'] = 'new name2'
jsonStr = jsonify(json)
return jsonStr
您可以使用Flask的
request.environ()
函数来获取客户端的远程端口和IP地址:装潢师会印一些东西,比如:
^{pr2}$相关问题 更多 >
编程相关推荐