Additional Template Filters¶
Nautobot uses 2 template engines internally, Django Template and Jinja2. Django Template is used to render the UI pages and Jinja2 is used for features such as computed fields, custom links, export templates, etc.
Jinja2 and Django Template are very similar, the main difference between them is the syntax of the template. Historically, Django Template has been the go-to solution to generate webpage in Django and Jinja2 is the industry standard outside of Django.
Both Django Template and Jinja2 can be extended with a library of functions, called
filters, that apply formatting or transformations to a provided input. Nautobot provides many built-in
filters, including network specific
filters from the netutils library.
Added in version 1.2.0
Netutils is an external library, maintained by Network to Code, that is focusing on providing a collection of functions for common network automation tasks.
Please check the netutils documentation to see the list of available functions.
All functions in Netutils are available in Nautobot in both Jinja2 filters and Django Template.
Nautobot Built-In Filters¶
The Nautobot project also provides the following built-in
filters that can be used in both Jinja2 and Django Template.
Given a list of n items, return a corresponding range of n integers.
Alternative to the built-in
title filter; capitalizes words without replacing letters that are already uppercase.
title("IP address") == "Ip Address", while
bettertitle("IP address") == "IP Address".
Return x/y (rounded).
Return the ideal foreground color (black
"#000000" or white
"#ffffff") given an arbitrary background color in RRGGBB format.
Return the static URL of the documentation for the specified model.
Access a specific item/key in a dictionary.
Return True if the user has at least one of the permissions in the list.
Return True if the user has all permissions in the list.
Humanize speeds given in Kbps. 1544 => "1.544 Mbps" 100000 => "100 Mbps" 10000000 => "10 Gbps"
Added in version 1.4.0
Render and link to a Django model instance, if any, or render a placeholder if not.
object.display if available, otherwise uses the string representation of the object.
If the object defines
get_absolute_url() this will be used to hyperlink the displayed object;
additionally if there is an
object.description this will be used as the title of the hyperlink.
Added in version 1.5.0
This filter now accepts an optional
field parameter, which allows you to use a field other than
object.display for the object representation if desired. For example, to display the object's
name field instead:
Return the specified Meta attribute of a model.
Convert a length from meters to feet.
Return x/y as a percentage.
Render a muted placeholder (
<span class="text-muted">—</span>) if value is falsey, else render the provided value.
Render HTML from a computed boolean value.
If value is (for example) a non-empty string or True or a non-zero number, this renders
<span class="text-success"><i class="mdi mdi-check-bold" title="Yes"></i></span>
If value is (for example) "" or 0 or False, this renders
<span class="text-danger"><i class="mdi mdi-close-thick" title="No"></i></span>
If value is None this renders
Render a dictionary as formatted JSON.
Render text as Markdown.
Render a dictionary as formatted YAML.
Get a value from Django settings (if specified) or Constance configuration (otherwise).
Split a string by the given value (default: comma)
Returns the hour offset of a given time zone using the current time.
Return the view name for the given model and action if valid, or None if invalid.
Return the view name for the given model and action. Does not perform any validation.