开发者

Get current url in Django View

开发者 https://www.devze.com 2023-03-19 00:04 出处:网络
I need to grab the domai开发者_StackOverflow中文版n for the current page in my Django view. build_absolute_uri() works great to get the full path (http://www.domain.com/path/to/somewhere) but is there

I need to grab the domai开发者_StackOverflow中文版n for the current page in my Django view. build_absolute_uri() works great to get the full path (http://www.domain.com/path/to/somewhere) but is there anyway to just simply get the http://www.domain.com?


You could try a combination of HttpRequest.get_host() to get the host:port ("www.domain.com") and HttpRequest.is_secure() to see if the request was made over http or https. This should allow you to reconstruct a URL like https://www.domain.com:8080

0

精彩评论

暂无评论...
验证码 换一张
取 消