Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Snippet for Django breadcrumbs
'context_processors': [
home = (_('Start'), 'home')
breadcrumbs_views = {'home': [home],
'index': [(_('Landing'), 'index')],
contact’: [home, (_(‘Contact’), ‘contact’')],
from django.core.urlresolvers import resolve
from django.conf.settings import breadcrumbs_views
def breadcrumbs(request):
Context processor for include general breadcrumb in the mains views
:return: dictionary with the breadcrumb for each view
view_name = resolve(request.path_info).url_name
if view_name in breadcrumbs_views:
return {'breadcrumbs': breadcrumbs_views[view_name]}
return {}
# Base.html
{% block breadcrumbs %}
{% include 'breadcrumbs.html'%}
{% endblock breadcrumbs %}
# Breadcrumbs.html
<div class="breadcrumbs">
{% for crumb in breadcrumbs %}
{% if not forloop.last %}
<a class="breadcrumb "href="{% url crumb.1 %}"> {{ crumb.0 }} </a>
{% else %}
<a class="breadcrumb current">{{ crumb.0 }}</a>
{% endif %}
{% endfor %}
Copy link

Rewzaw commented Aug 11, 2020

why you're not rendering breadcrumbs.html in breadcrumbs view?

Copy link

iPablo commented Aug 11, 2020

This gist has 4 years, maybe my code is older for new django versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment