F
F
fantom_ask2020-08-29 15:33:08
Django
fantom_ask, 2020-08-29 15:33:08

How to access variable or functions from html template?

I just started learning django and I couldn't find anything in the documentation or on the internet.
I know that I can access a variable or function by putting it in views.py and sending it to

return render(request, 'html.html', {'args':args })

But what if I need to access the variable from all my applications. I have to write the same thing over and over again.
I would like to do it more neatly like this
<!--для переменных-->
<div>
{% load TEST %}
TEST
</div>
<!--для функций -->
<div>
{% load TEST %}
TEST(1,2)
</div>
<!--для списков-->
<div>
{% load TEST %}
TEST[0]
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-08-29
@fantom_ask

1. Write your own context processors https://docs.djangoproject.com/en/3.1/ref/template...
2. You can't explicitly call functions in the template, just write your own tag or filter https://docs.djangoproject.com /en/3.1/howto/custom...
3. In the template, lists can be accessed asTEST.0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question