python使用Flask框架获取用户IP地址有什么办法
python使用Flask框架获取用户IP地址有什么办法呢?读了下面小编整理的'内容或许解决您的问题。更多内容请关注应届毕业生考试网!
下面的代码包含了html页面和python代码,非常详细,如果你正使用Flask,也可以学习一下最基本的Flask使用方法。
python代码如下:
from flask import Flask, render_template, request
# Initialize the Flask application
app = Flask(__name__)
# Default route, print user's IP
@app.route('/')
def index():
ip = request.remote_addr
return render_template('index.html', user_ip=ip)
if __name__ == '__main__':
app.run(
host="0.0.0.0",
port=int("80")
)
html代码如下:
?
<!DOCTYPE html>
<html lang="en">
<head>
<link href="bootstrap/3.0.0/css/bootstrap.min.css"
rel="stylesheet">
</head>
<body>
<P class="container">
<P class="header">
<h3 class="text-muted">How To Get The IP Address Of The User</h3>
</P>
<hr/>
<P>
You IP address is: <strong>{{user_ip}}</strong>
<P class="header">
<h3 class="text-muted">Code to retrieve the IP</h3>
</P>
<hr/>
<pre>
from flask import Flask, render_template, request
# Initialize the Flask application
app = Flask(__name__)
# Default route, print user's IP
@app.route('/')
def index():
ip = request.remote_addr
return render_template('index.html', user_ip=ip)
</pre>
</P>
</P>
</body>
</html>
【python使用Flask框架获取用户IP地址有什么办法】相关文章:
win7 ip地址设置12-14
IP地址的子网如何划分09-27
IP地址计算和子网划分09-23
如何使用PHP框架09-30
php获取当前url地址的方法08-16
查看路由器IP地址方法12-20
ip地址计算与子网划分详解09-18
如何管理局域网IP地址12-12
win7 ip地址冲突怎么解决11-30