Previous Page Next Page

Q&A

Q.Is there a way to add one numeric variable to another in a template?
A.Yes. The add filter can be applied to a variable to add another variable to it using the following syntax:
{{ varA|add:varB }}

Q.Is there a way to retrieve a specific digit from a numeric variable?
A.Yes. The get_digit filter retrieves a specific digit based on a numeric argument, where an argument with a value of 1 is the rightmost digit:
{{ varA|get_digit:"1" }}

Q.Is there a quick way to add HTML markup to an URL that is in plain text so that it will be rendered as a clickable link?
A.Yes. The urlize filter adds HTML markup to a plain-text URL:
{{ myURL|urlize }}

Q.Are any other filter libraries available for templates?
A.Yes. You can add the django.contrib.humanize, django.contrib.markup, and django.contrib.webdesign libraries to the INSTALLED_APPS setting and load them into the templates using the following load tag syntax:
{% load humanize %}

Previous Page Next Page