5 ms·
I would add to this list: convert your template engine to Jinja2. I held out for a long time on this, and now I would not go back. The purist approach ("keep lo
by nojs 4y ago
I would add to this list: convert your template engine to Jinja2. I held out for a long time on this, and now I would not go back. The purist approach ("keep logic out of templates") sounds good, but in practice leads to spaghetti hacks with weird additional template tags to do simple things, a bunch of additional context variables with no meaning, etc.
- 41b696ef1113 4y agoAs another hold-out on Jinja, what pushed you over the edge? Half of the appeal to me in Django is that if you follow the easy path, one project should look like another. Breaking conventions for a few template niceties has not seemed worth it (although, I am not a front end guy, and survive on very barebones presentation).
- nojs 4y ago> what pushed you over the edge? Using Tailwind without a frontend js framework. I needed a way to create lightweight “components” ala React but on the backend, because otherwise you’re either copy pasting classes like mad or (ab)using tailwind’s @apply.
- jereze 4y agoHow do you create your components in Jinja2? Using the include tag?
- nojs 4y agoI am using {% macro %}
- drcongo 4y agoI've been gradually removing all use of Jinja macros from our projects as they make debugging so much more painful. Everything now goes in template globals, which lets you debug them the same as anything else, gives far clearer stack traces and lets you do clever things with caching.
- spapas82 4y agoI had used this project for creating components https://github.com/EmilStenstrom/django-components/ https://github.com/EmilStenstrom/django-components/ Also, for simpler cases I include partial templates.
- raverbashing 4y ago> purist approach ("keep logic out of templates") sounds good, but in practice leads to spaghetti hacks This. Exactly this Go for Jinja2 and don't look back If there's one defect in Django is the rosy-colored purist view that permeates a lot of its design decisions. Keeping "logic only in code" made sense in the 90s. And no, I'm not building a new template tag every time I make some stylistic choice.
- spapas82 4y agoAbout the purist view on Django: The django templates don't annoy me that much, but what is really annoying is the avoidance of using thread locals in Django. This makes very difficult stuff that would be trivial in other frameworks (ie flask), like getting the current user.