I found that the tag {% url path.to.view %}can only return the path to the URL, how can I get the full URL with the domain name?
In fact, I want to add a link that points to a different view of my site. But {% url path.to.view %}can only get the path to my view. As a result, the link cannot indicate what I want.
My solution uses HttpRequest.get_host()in the first view to get the domain and pass it to the template by Context. Then in the template (html file) connect to the full URL. Example <a href="http://{{ domain }}{% url path.to.view %}?param={{param}}">Foo</a>.
In short, I just want to get a domain. Sorry for my fuzzy description! @Hans answer is great, thanks!
source
share