Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twig for Django

I am looking for Twig documentation for Django and I haven't found much. I have read about Twig for PHP especially for Symfony 2. I have some queries about Twig, for instance:

  1. I would like do a loop over an array like {% for i in range(5) %}, but it doesn't work for me.
  2. Is there a filter to capitalize words, like | upper or | lower. Maybe ucfirst or wcword? I am a PHP programmer, and this is what I'm used to.
  3. I have been trying to work with static in my templates. I have tried {% load static %}, but when I include a static element like a javascript file or stylesheet, for instances, <script href="{{ static "js/file.js"}}" ></script>, Django always throws an exception related to rendering it.
like image 300
Jorge Avatar asked Dec 07 '22 07:12

Jorge


1 Answers

It only makes sense that you haven't found any documentation for using Twig with Django because there is none! Twig is a PHP templating engine that uses a syntax similar to the Django templating system. This is the source of your confusion, from what I see.

Check out the Django templating system documentation for the actions you want to perform.

like image 142
Assil Avatar answered Jun 13 '23 12:06

Assil