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

首頁(yè) > 編程 > Python > 正文

python使用Flask框架獲取用戶(hù)IP地址的方法

2019-11-25 17:55:10
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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

下面的代碼包含了html頁(yè)面和python代碼,非常詳細(xì),如果你正使用Flask,也可以學(xué)習(xí)一下最基本的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>

希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 茂名市| 洞头县| 霸州市| 江西省| 任丘市| 甘德县| 兰西县| 遂溪县| 什邡市| 清苑县| 唐海县| 左权县| 南郑县| 会宁县| 饶阳县| 上饶市| 通辽市| 巴东县| 汝州市| 扶余县| 临洮县| 来凤县| 三门县| 兴海县| 岱山县| 神农架林区| 津市市| 西乡县| 伊宁市| 新巴尔虎左旗| 华蓥市| 东乡县| 鹤壁市| 吉木乃县| 保德县| 新丰县| 米林县| 阿勒泰市| 全椒县| 河东区| 米林县|