django-dynamic-breadcrumbs
is a Django app to generate HTML breadcrumbs
dynamically from URL paths.
At https://example.com/reference/instrument/guitar/
, shows:
Home > Reference > Instrument > Guitar
.
pip install django-dynamic-breadcrumbs
Add "dynamic_breadcrumbs" label to your INSTALLED_APPS settings:
INSTALLED_APPS = [
...
'dynamic_breadcrumbs',
]
Add dynamic_breadcrumbs.context_processors.breadcrumbs
to context_processors:
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
#...
"dynamic_breadcrumbs.context_processors.breadcrumbs",
],
},
},
]
Include the dynamic_breadcrumbs/breadcrumbs.html
in your base template.
{% if breadcrumbs %}
<div class="container">
{% include "dynamic_breadcrumbs/breadcrumbs.html" with breadcrumbs=breadcrumbs%}
</div>
{% endif %}
Now each time you visit a page which makes use of the above template, it will have the breadcrumbs generated from the URL path.
Tweak default settings.
There is an example site to see how it works at example_site. To
run it, in example_site
directory:
- Create db:
python manage.py migrate
- Load fixtures
python manage.py loaddata fixtures.json
- Run the server
python manage.py runserver
Note: Fixtures were created with a sample database with ./manage.py dumpdata --all --format json -o fixtures.json
.
Full docs at: https://django-dynamic-breadcrumbs.readthedocs.io/
MIT