Can Django's URL tag show the URL of the RedirectView
Let's say that in my urls.py I have a url like this:
path("support/", RedirectView.as_view(url="http://www.example.com"), name="support"),
And in one of my templates I use the url tag:
{% url "support" %}
This of course renders /support/
as expected. But what if I want it to render http://www.example.com
instead? Is that at all possible? Skip the redirect basically.
But what if I want it to render http://www.example.com instead? Is that at all possible? Skip the redirect basically.
No, in short it is not possible with django views, since the url is of another website and you can't render it in your own.
You can see what exactly render()
does.
If you'd like to directly redirect, then simply use anchor tag as:
<a href="http://www.example.com">Visit website.</a>
You can also do this dynamically, by creating a URLField
in one of the models and simply iterating it with href
attribute of anchor tag.