使用Flask for Python获取访问者的IP地址 [英] Get IP address of visitors using Flask for Python
问题描述
我正在建立一个网站,用户可以使用烧瓶微框架登录和下载文件 (基于 Werkzeug )使用Python(在我的情况下为2.6).
我需要获得用户登录时的IP地址(出于记录目的). 有谁知道如何做到这一点?当然有办法用Python做到这一点吗?
请参见 有关更多信息,请参见 Werkzeug文档. /p> I'm making a website where users can log on and download files, using the Flask micro-framework (based on Werkzeug) which uses Python (2.6 in my case). I need to get the IP address of users when they log on (for logging purposes).
Does anyone know how to do this? Surely there is a way to do it with Python? See the documentation on how to access the Request object and then get from this same Request object, the attribute Code example For more information see the Werkzeug documentation. 这篇关于使用Flask for Python获取访问者的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!remote_addr
.from flask import request
from flask import jsonify
@app.route("/get_my_ip", methods=["GET"])
def get_my_ip():
return jsonify({'ip': request.remote_addr}), 200