【Django】リクエストからURLを取得する方法

フルパス取得

url = f'{request.scheme}://{request.get_host()}{request.path}'

https://417.run/hoge/

フルパス取得(パラメータあり)

url = request.build_absolute_uri()

https://417.run/hoge/?h=0

スキーム(httpとか)取得

request.scheme

https

ホスト(google.comとか)取得

request.get_host()

417.run

パスの取得

request.path

/hoge/

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です