2013-04-12 7 views

答えて

131

あなたは、いくつかのRequest fieldsを通じてURLを調べることができます:上記の属性の値は、次のようになります。この場合

http://www.example.com/myapplication/page.html?x=y 

を利用者には、以下のURLを要求します

path    /page.html 
    script_root  /myapplication 
    base_url   http://www.example.com/myapplication/page.html 
    url    http://www.example.com/myapplication/page.html?x=y 
    url_root   http://www.example.com/myapplication/ 

あなたは簡単に追加できます適切な分割を使用してホスト部分を処理します。

+5

の代わりに、 '' 私は 'Request.root_url'を取得しようとしていますし、リターンとして、私は唯一の取得'http:// www.example.com/myapplication /'という形式で整形されています。または、この機能はlocalhostでは動作しませんか? – Vadim

+2

@ Vadim Request.root_urlではなく、request.root_urlを使用する必要があります。 – selfboot

+0

Flaskに新しい、私は要求オブジェクトがどこから来て、どのように動作するのかわかりませんでしたが、ここにあります:http://flask.pocoo.org/docs/0.12/reqcontext/ –

7

あなたは試してみてください:

request.url 

それも、ローカルホスト上で、常に動作すると仮定(ちょうどそれをしませんでした)。

25

別の例:

その後、
request: http://127.0.0.1:5000/alert/dingding/test?x=y 

request.url:     http://127.0.0.1:5000/alert/dingding/test?x=y 
request.base_url:   http://127.0.0.1:5000/alert/dingding/test 
request.url_charset:   utf-8 
request.url_root:   http://127.0.0.1:5000/ 
str(request.url_rule):  /alert/dingding/test 
request.host_url:   http://127.0.0.1:5000/ 
request.host:    127.0.0.1:5000 
request.script_root: 
request.path:    /alert/dingding/test 
request.full_path:   /alert/dingding/test?x=y 
関連する問題