[Django]-What does this "-" in jinja2 template engine do?

53👍

It suppresses extra vertical spacing, commonly used when you don’t want excessive spacing between elements you’re looping through.

If you put an minus sign (-) to the start or end of a block (for
example a for tag), a comment or variable expression you can remove
the whitespaces after or before that block

See: http://jinja.pocoo.org/docs/templates/#whitespace-control

6👍

As you implied the Google App Engine and Django use Jinja.
Jinja uses the dash to remove or add whitespace within a block.
{%- by itself means current line should have no empty lines between current and previous line
-%} by itself means current line should have a single empty line above it
{%- and -%} means current line should be flush with previous line

In your example, you have dashes for the for loop. This will leave no space between the items. If you did not have this dash, it will leave a blank space between each item.

You can experiment here:
http://jinja.quantprogramming.com

Additional links:
Documentation
Credit

Leave a comment