国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python使用Flask框架獲取用戶IP地址的方法

2020-02-23 00:25:11
字體:
來源:轉載
供稿:網友

本文實例講述了python使用Flask框架獲取用戶IP地址的方法。分享給大家供大家參考。具體如下:

下面的代碼包含了html頁面和python代碼,非常詳細,如果你正使用Flask,也可以學習一下最基本的Flask使用方法。

python代碼如下:

from flask import Flask, render_template, request# Initialize the Flask applicationapp = 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>  <div class="container">   <div class="header">    <h3 class="text-muted">How To Get The IP Address Of The User</h3>   </div>   <hr/>   <div>    You IP address is: <strong>{{user_ip}}</strong>  <div class="header">    <h3 class="text-muted">Code to retrieve the IP</h3>   </div>   <hr/>  <pre>from flask import Flask, render_template, request# Initialize the Flask applicationapp = 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>   </div>  </div> </body></html>

希望本文所述對大家的Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 荃湾区| 平湖市| 宁明县| 金寨县| 广东省| 新津县| 什邡市| 平阳县| 综艺| 滕州市| 乌审旗| 镶黄旗| 巴彦县| 吉木乃县| 普安县| 广西| 横山县| 哈密市| 黄冈市| 嵊州市| 凤城市| 沙河市| 临桂县| 定陶县| 军事| 古丈县| 德清县| 宁城县| 江门市| 米泉市| 广宗县| 连云港市| 灵山县| 工布江达县| 襄城县| 涡阳县| 甘泉县| 福安市| 曲水县| 通化市| 汉川市|