2016-12-07 48 views
0

Flask Python Webに自分のIPアドレスを表示する際に問題があります。アナロジーは、PHPプログラミングの場合は、単に私のIPアドレスをFlaskに表示するには?

echo $_SERVER['SERVER_ADDR'];

を使用する非常に簡単ですが、私は、PythonのWebフラスコにIPアドレスを起動する方法がわかりません。私が表示したいのに対し、192.168.43.46:4000上で実行されている

用途:

:フラスコ

<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> 

とで使用

<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> 

スクリプトは、クライアント側のブラウザに登場しました

表示方法:

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

フラスコ?

+0

あなたは '使用する場合、ブラウザは何を見ん{{request.script_root}} '? –

+0

'request.remote_addr' – furas

+0

ブラウザ参照: ' {{request.script_root}} '= 'http://192.168.43.46:4000' –

答えて

1

要求オブジェクトには.host属性がありますが、使用可能であればポート番号も含まれています。ちょうどホスト名またはIPアドレスを取得するには、試してみてください。

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

を別の方法として、あなたが照会できWSGI environment直接:

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

woow .... thanks @Robᵩ。 この作品は、 'src =" http:// {{request.host.split( ':')[0]}}/vshell/index.php?type = services&clearcache = true "' –

関連する問題