I have to build an url dynamically according to the current url. Using the {% url %}
tag is the easiest way to do it, but I need the current url namespace to generate the new one dynamically.
How can I get the url namespace attached to the urlconf that leads to the current view?
EDIT : I know I can manually handcraft the url using get_absolute_url
but I'd rather avoid it since it's part of a lecture and I would like to demonstrate only one way to build urls.
The students know how to use {% url %}
. They are know facing a problem when they have to generate a more complete url based on the current one. The easiest way is to use {% url %}
again, with some variations. Since we have named url, we need to know how to get the name of the url that called the current view.
EDIT 2: another use case is to display parts of the base template différently according to the base template. There are other ways to do it (using CSS and {% block %}, but sometime it just nice to be able to remove the tag of the menu entry of base.html if the viewname match the link.
{{ request.get_full_path }}
– Strenta