Reference¶
For class attributes, method signatures, and type information, see the API Reference.
This page documents the runtime behaviors that aren’t captured in the API docs.
Template Tag¶
{% load django_simple_nav %}
{% django_simple_nav nav [template_name="..."] %}
Argument |
Required |
Description |
|---|---|---|
|
yes |
A dotted import path string to a |
|
no |
Override the template used to render the navigation. Passed as a keyword argument: |
Expects request in the template context.
Jinja2 Function¶
See Jinja2 for setup and usage.
def django_simple_nav(nav: str | Nav, template_name: str | None = None) -> str:
...
Same arguments as the template tag. Must be registered in the Jinja2 environment’s globals.
Template Resolution¶
Nav.render() resolves the template through these methods, in order:
Method |
Default behavior |
Override to… |
|---|---|---|
|
Calls |
Return an inline template string, add caching, or customize loading. |
|
Returns |
Choose a template dynamically at runtime. |
If get_template() returns a string instead of a template object, render() compiles it as an inline template using the configured template engine.
See Customizing Template Resolution for examples.
Template Context¶
The template specified by Nav.template_name receives:
Variable |
Type |
Description |
|---|---|---|
|
|
Top-level navigation items. |
Each item in the list exposes:
Variable |
Type |
Description |
|---|---|---|
|
|
The item’s title. |
|
|
Resolved URL. Empty string for a |
|
|
Whether this item matches the current request. |
|
|
Child items for |
extra_context keys |
|
Any additional keys from |
Items are also self-rendering: {{ item }} renders the item using its own template. See Self-Rendering Items.
URL Resolution¶
When a url is provided, it is resolved in this order:
Promise(e.g.reverse_lazy): converted to a string.Callable: called with no arguments; the return value is used.
String: passed to
django.urls.reverse(). IfNoReverseMatchis raised, the string is used as a literal URL.
After resolution, the trailing slash is adjusted based on append_slash:
None: usessettings.APPEND_SLASH.True: always appends a slash to the path.False: never appends a slash to the path.
The slash logic applies only to the path component — query strings, fragments, and absolute URL schemes are preserved.
Active State¶
An item is considered active when its resolved URL matches the current request.
Condition |
Rule |
|---|---|
Path |
Exact match only. No prefix matching. |
Query parameters |
Must match exactly (parsed as dictionaries). |
Scheme and host |
For absolute URLs, must match the request. Relative URLs compare only the path. |
|
Active if its own URL matches or any descendant is active. |
Permission Evaluation¶
See Permissions for practical examples.
Permissions are evaluated in order. All must pass (AND logic).
Permission type |
How it’s checked |
|---|---|
|
Read as a boolean attribute on |
|
Checked via |
Callable |
Called with |
Special cases:
Superuser short-circuit: if
request.user.is_superuserisTrue, all permission checks pass immediately.No
django.contrib.auth: all permission checks are skipped; every item is shown.No
request.user: items with permissions are hidden; items without permissions are shown.
Settings¶
DJANGO_SIMPLE_NAV = {
"TEMPLATE_BACKEND": None, # default
}
Key |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Full path of the template backend to use (e.g. |