I need custom template tag inside model.TextField value. Value from the object text field have something like "lorem ipsum dolor {% mytag %}" but “mytag” is not rendered as template tag. It is registered in the library as tag and loaded on the page and I have {{ object.textfield|safe }} filter. Is it possible at all?
I need custom template tag inside model.TextField value. Value from the object text field
Share
As Django’s template engine can easily be used anywhere in your code you should be able to do something like this:
Rather than rendering the template from a file it renders it from a string like:
The code can for instance be used in your view or as a method on your model. Note that the
Contextis empty, you might as well pass a dict with template variables to it.Furthermore, to handle it directly in the template you could write a custom templatetag which does something similiar, basically a templatetag that parses strings for templatetags.