Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current url in Django View

I need to grab the domain 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?

like image 465
Brenden Avatar asked Nov 21 '25 14:11

Brenden


1 Answers

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

like image 105
vinod Avatar answered Nov 23 '25 06:11

vinod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!