Answer the question
In order to leave comments, you need to log in
How to execute a tag in a template that was passed to it as a string?
Passed a variable to the Django template x = 'Text {{ data }} text'
Called it in the template: {{ x }}
It was displayed as Text {{ data }} text
And how can I make {{ data }} from this line be processed as a tag and that the value from the data variable would be displayed?
Answer the question
In order to leave comments, you need to log in
I made a filter, suddenly someone will come in handy
from django import template
register = template.Library()
@register.filter(name='string_replace')
def string_replace(string, value):
return string.replace('{{ data }}', value)
{% load string_replace %}
{{ x | string_replace:data }}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question