Answer the question
In order to leave comments, you need to log in
How to use variables inside {% url ' ' %} in template?
Hey!
My three templates do exactly the same thing. Only the link to the action differs. I was hoping that by simply adding variables to the view ( url and object_id ) I would be able to reduce the number of templates to one.
Sample:
<form action="{% url 'user_resume:{{ url }}' {{ object_id }} %}" method='post'>
Answer the question
In order to leave comments, you need to log in
Make a variable in the view that will contain the required url.
The url can be obtained like this https://docs.djangoproject.com/en/1.11/ref/urlreso... Place
logic, even such a simple one, better in view
Template should be blunt
First, within a django tag {% %}
, variables are used simply by name, without the enclosing double brackets - {% url 'user_resume' {{ object_id }} %}
. Secondly, the first parameter of this tag (url name) cannot be dynamic.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question