I found the tag {% url path.to.view %}
can only return the path of URL, how can I get the full URL with domain name?
Actually, what I want to do is, adding a link which point to another view of my site. But {% url path.to.view %}
can only get the path of my view. In result, the link cannot point to what I want.
My solution is using HttpRequest.get_host()
in first view to get domain and pass it to template by Context. Then, in template(html file), splice to the full url address. Like this:<a href="http://{{ domain }}{% url path.to.view %}?param={{param}}">Foo</a>
.
In short, I just want to get domain. Sorry for my unclear description! @Hans's answer is great, thank you!
That's in the docs here:
Use the method build_absolute_uri()
on the request object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With