Skip to content
Breadcrumb mixins for django generic views.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
demo
view_breadcrumbs Removed assert. Jan 13, 2019
.bumpversion.cfg
.coveragerc
.gitignore
.pypirc Updated .pypirc Aug 19, 2018
.travis.yml Updated the test config and removed unused packages Aug 19, 2018
LICENSE
MANIFEST.in Modified the .gitignore Mar 1, 2018
Makefile Remove pypandoc Aug 19, 2018
README.md
breadcrumbs.png
conftest.py
manage.py
pytest.ini
requirements.txt Removed django dependency. Jan 26, 2019
setup.py "2019-01-27 15:05 - Increased django-view-breadcrumbs version: VERSIO… Jan 27, 2019
tox.ini Merge pull request #29 from jackton1/develop Jan 26, 2019

README.md

django-view-breadcrumbs Build Status Codacy Badge PyPI version

This extends django-bootstrap-breadcrumbs providing generic breadcrumb mixin classes.

Requires adding {% breadcrumb $label $viewname [*args] [**kwargs] %} to only the base template.

Screenshot

In the base.html template simply add the render_breadcrumbs tag and any template that inherits the base should have breadcrumbs included. i.e

base.html

{% load django_bootstrap_breadcrumbs %}

{% block breadcrumbs %}
    {% render_breadcrumbs %}
{% endblock %}

And your create.html.

{% extends 'base.html' %}

Breadcrumb mixin classes provided.

  • BaseBreadcrumbMixin - Base view requires a crumbs class property.
  • CreateBreadcrumbMixin - For create views Home \ Posts \ Add Post
  • DetailBreadcrumbMixin - For detail views Home \ Posts \ Post 1
  • ListBreadcrumbMixin - For list views Home \ Posts
  • UpdateBreadcrumbMixin - For Update views Home \ Posts \ Post 1 \ Update Post 1

Installation:

$ pip install django-view-breadcrumbs

Add app to your INSTALLED_APPS

INSTALLED_APPS = [
    ...
    'django_bootstrap_breadcrumbs',
    'view_breadcrumbs',
    ...
]

Usage:

django-view-breadcrumbs includes generic mixins that can be added to a class based view.

Using the generic breadcrumb mixin each breadcrumb will be added to the view dynamically and can be overridden by providing a crumbs property.

Sample crumbs: Home \ Posts \ Test - Post

NOTE: All url config should use a pattern view_name=model_verbose_name_{action} i.e view_name=post_detail for detail view.

Actions include:

  • "list" - ListView
  • "change" - UpdateView
  • "detail" - DetailView

In your urls.py

  urlpatterns = [
      ...
      path('posts/<slug:slug>', views.PostDetail.as_view(), name='post_detail'),
      ...
  ]

views.py

from django.views.generic import DetailView
from view_breadcrumbs import DetailBreadcrumbMixin


class PostDetail(DetailBreadcrumbMixin, DetailView):
    model = Post
    template_name = 'app/post/detail.html'

All crumbs use the home root path \ as the base this can be excluded by specifying add_home = False

Sample crumbs: Posts

from django.views.generic import ListView
from view_breadcrumbs import ListBreadcrumbMixin


class PostList(ListBreadcrumbMixin, ListView):
    model = Post
    template_name = 'app/post/list.html'
    add_home = False

Can also override the view breadcrumb by specifying a list of tuples [(Label, view path)].

Custom crumbs: Home \ My Test Breadcrumb

URL conf.

urlpatterns = [
   path('my-test-list-view/', views.TestView.as_view(), name='test_list_view'),
   path('my-test-detail-view/<int:pk>/', views.TestView.as_view(), name='test_detail_view'),
]

views.py

from django.urls import reverse
from django.views.generic import ListView
from view_breadcrumbs import ListBreadcrumbMixin


class TestView(ListBreadcrumbMixin, ListView):
    model = TestModel
    template_name = 'app/test/test-list.html'
    crumbs = [('My Test Breadcrumb', reverse('test_list_view'))]  # OR reverse_lazy

OR

class TestView(ListBreadcrumbMixin, ListView):
    model = TestModel
    template_name = 'app/test/test-list.html'

    @cached_property
    def crumbs(self):
        return super(TestView, self).crumbs + [
            (self.object.name , reverse('test_detail_view', kwargs={'pk': self.object.pk})
        ]
You can’t perform that action at this time.