url (alt=None, absolute=None, external=None, resolve=None, strict_resolve=None)

This filter is the most useful filter for URL generation and it comes in two flavors. It takes one optional argument which is the alt if it should differ from the current one (see Alternatives). The filter can be applied to either a string or a Record object.

Note that the URL filter operates on paths as they exist in your tree, not as the final URLs. This is important when a page forcefully overrides the URL path. In this case it could be that linking to /project for instance would generate the URL de/projekte/ if that's what's configured.

To override this behavior, pass resolve=False (or, alternatively, prefix the URL with !) and no resolving will take place.

Note that, by default, the URL filter always generates a relative URL. So for instance if you are currently at /info/about/ and you want to link to /projects/ it will generate a link in the form of ../../projects/. This makes it possible to easily deploy the website to a folder outside of the root of the website.


<ul class="nav">
  <li><a href="{{ '/'|url }}">Index</a></li>
  <li><a href="{{ '/about'|url }}">About</a></li>

Same page to other alternative:

<a href="{{ '.'|url(alt='ru') }}">Русский</a>

If you already know 100% where to link to, and you do not want any resolving to take place, then pass resolve=False. For instance this always links to the root of the website:

<a href="{{ '/'|url(resolve=False) }}">To Root</a>


Internally, this filter uses SourceObject.url_to. See the documentation for that method to read more about the details of that process.