簡體   English   中英

如何在Flask上顯示我的IP地址?

[英]How to show my IP Address on Flask?

我在Flask Python Web上顯示我的IP地址時遇到問題。 打個比方,如果在PHP編程中很容易就可以使用

echo $_SERVER['SERVER_ADDR'];

但是我不知道如何在Python Flask Web中顯示IP地址。

應用程序在192.168.43.46:4000上運行,而我想顯示:

<iframe id="form-iframe" src="http://192.168.43.46/vshell/index.php?type=services&clearcache=true" style="margin:0; width:100%; height:640px; border:none; overflow:hidden;" onload="AdjustIframeHeightOnLoad()"></iframe>

燒瓶中使用的腳本

<iframe id="form-iframe" src="{{ request.script_root }}/vshell/index.php?type=services&clearcache=true" style="margin:0; width:100%; height:640px; border:none; overflow:hidden;" onload="AdjustIframeHeightOnLoad()"></iframe>

並且出現在客戶端瀏覽器上:

如何顯示:

src="http://192.168.43.46/vshell/index.php?type=services&clearcache=true"

在燒瓶上?

該請求對象具有.host屬性,但包括端口號(如果有)。 要僅獲取主機名或IP地址,請嘗試:

{{ request.host.split(':')[0] }}

或者,您可以直接查詢WSGI環境

{{ request.environ['SERVER_NAME'] }}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM