Jinja2

Describing Standard Filters

  • Filters are operations that modify variables
  • Filters are separated by a variable using the \vert operator
  • Multiple filters can be chained together
  • The output of one filter is applied to the next
  • For example, the {{ x|join(, ) }} uses a filter
  • It joins a list xx with commas
  • The tojson filter is useful for generating JavaScript on the fly:
<script type=text/javascript>
    doSomethingWith({{ user.username|tojson }});
</script>

Controlling Autoescaping

  • Autoescaping refers to automatically escaping special characters
  • Special characters in HTML refer to:

    • &\And
    • >>
    • <<
    • ""
    • '
  • These characters carry specific meaning in documents
  • Therefore, they need to be replaced by entities for displaying them as text

References

Previous
Next

Templates

Logging