S
S
StopDesign2011-03-27 17:09:06
Django
StopDesign, 2011-03-27 17:09:06

Are macros necessary in Django templates?

Hello.
There is a question. How to make DRY without macros in templates, while remaining within the framework of the template engine, and not leaving view.py?
As you know, there are no macros in django-templates. And I want to place a complex search form in two places on the page. How to be?
There is a funny opinion in the community that "if something is not implemented, then this is a bad approach." Macros are clearly not implemented (although there has been a snippet for four years ). Is this a bad approach? Are you using this approach? If you don't use it, please tell me how to do it.
Let me explain where this question comes from. A long time ago I decided to use Jinja2 as my Django templating engine. After two years of such work, I realized that the main plus that he (she?) Provides - rendering speed - is covered by many shortcomings: lack of support from the IDE, inconvenience of template debugging, slow development, inconvenience of creating tags and filters, etc. I returned to django-templates, but there are no macros and poor if.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vlad Frolov, 2011-03-27
@frol

The inclusion tag seems to fit the best .
PS Nothing wrong with snippets IMHO

S
savados, 2011-03-28
@savados

In 1.3, it became possible to pass variables to the include tag in the spirit of
{% include "name_snippet.html" with person="Jane" greeting="Hello" "%}
Although it is more correct to use the inclusion tag, as suggested above.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question