Eric Wilson's Blog

Experiments in engineering, life and the pursuit of a better hammer.

Eric Wilson's blog discussing Product Development and Software Engineering.

  • Blog
  • Snippets
  • About
  • Contact
  • Search

Django Template's "with" Statement

April 13, 2013 by Eric Wilson in software

You can use Django template's "with" statement to calculate values. This is an elegant approach as it removes the need for many "if" statements.

Example: Put a border around a specific kind of image on a page.

Using the conditional style:

​Using the calculation style:


April 13, 2013 /Eric Wilson
django, python, web, template
software
This work is licensed under a Creative Commons License and is the private blog of Eric Wilson.
The opinions are my own and are not endorsed by my current or former employers or colleagues.
Creative Commons License