Sometimes, we want to get IP address of visitors using Flask for Python.
In this article, we’ll look at how to get IP address of visitors using Flask for Python.
How to get IP address of visitors using Flask for Python?
To get IP address of visitors using Flask for Python, we can use the request.remote_addr
property.
For instance, we write
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
to get the client’s IP address with the request.remote_addr
property.
Conclusion
To get IP address of visitors using Flask for Python, we can use the request.remote_addr
property.