R
R
R.2017-08-25 10:24:00
Django
R., 2017-08-25 10:24:00

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'>

What are the ways to solve this problem and remove unnecessary templates?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2017-08-25
@ron6500

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

S
Sergey Gornostaev, 2017-08-25
@sergey-gornostaev

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 question

Ask a Question

731 491 924 answers to any question