I have some child templates which extends one base template. I can access {{ view.kwargs }} inside the child template but when I use it inside the base template its value is empty. I have searched it on stack overflow and web but couldn’t find a solution.
view.kwargs.xyz contains the argument part in my url
My urls.conf
path('test/<str:xyz>/', SomeViewName, name='test-xyz')
,
URL: https://somedomain/test/demovalue/
Base Template
basetemplate.html
<html>
...
{{ view.kwargs.xyz }} ---> This value is empty
...
</html>
Child Template
{% extends "basetemplate.html" %}
{% block nav %}
{{ view.kwargs.xyz }} ---> This displays the expected value ie. demovalue
{% endblock %}
I need to access view.kwargs inside base template because there is a url in base template to which i need to send a parameter from view.kwargs
<a href="{% url 'test-xyz' view.kwargs.xyz %}">link</a>
This code is not working in base template as view.kwargs is empty.
Could anyone help me how to fetch view.kwargs inside base template or is there any work around.
Thanks.