A
A
Andrei1penguin12020-11-22 19:51:32
Django
Andrei1penguin1, 2020-11-22 19:51:32

How to access an element on a page from django templates?

Good day, I will explain the problem with a small example

. There is html:

<div data="10">
    <div> {{ value.filter(id=x) }} </div>
</div>


Task:
There is a queryset of certain elements that have an id
Without going into details, the id of the desired element is entered into the attribute of the parent data block using javascript, in the example this value is 10
And I need to substitute this value in place of "x", that is, it should work value.filter(id=10)
Therefore, you need to somehow execute javascript in the templates, like, I have no idea

. I have something like the following plan (which I'm not sure at all) implementation:
Do {{ value|my_filter }}, and define the my_filter filter in the file with filters according to the following concept:
Find out the data attribute of the open window (a priori there can be only one, this is a modal window for the entire page), then return the attribute value to the template
What confuses me in this method is whether I can access the current state of the page from the filter, or not, and in principle I’m not sure about the correctness of the solution.
If anyone knows how to do this better, please help

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question