Description
This tool is a Django application that generates "Breadcrumbs" of the page it is installed on. Due to the peculiarity of the Django framework, all generation occurs on the server, i.e. SSR rendering method.
Installation and Setting up
To install this package, you can download the source code from this site or via PyPi:
After installation, you need to connect the application and the corresponding middleware in settings.py:
Now, in order for this application to find the pages to add breadcrumbs to, your views will need to return a TemplateResponse object. For example, I have a default article view that returns an HttpResponse using the render shortcut function:
Instead of the render function, you need to substitute TemplateResponse. Like this:
We are done with setting up and installing the necessary django application. Now, about how and where to insert the breadcrumb template.
A usage guide
To use this application, you need to insert the appropriate template block where you would like to see breadcrumbs. Here is the block:
As you can see, the application defines a variable isBreadcrumbsMiddlewareConnected to know whether the application is connected or not. Then there are the following variables that you can send to the server for rendering:
- separator - what symbol will separate each of the path elements
- first_separator - this is the very first character that will be before the first element
- last_separator - this is the very last character that will be after the last element
- custom_urls - another variable is the list of addresses you would like to render instead of the generated one
It will look something like this:

I also defined several CSS classes for additional styling of the breadcrumbs:
- breadcrumbs-container - for the entire container
- breadcrumbs-separator-first - for the first separator
- breadcrumbs-separator - for all separators
- breadcrumbs-separator-last - for the las separator
How it works
Most django apps that implement the breadcrumb element do so by passing a list of items in the views themselves. My app works differently.
The source for the breadcrumb items is the HTTP_REFERER key-value pair in the META dictionary in the request itself:
After the referring URL has been received, it is processed and returned to special templates for rendering. I would like to note that due to the peculiarities of the address source, i.e. HTTP_REFERER, if you go to the page via Google search or directly by entering the address in the search bar, no breadcrumbs will appear.
This is what the templates for rendering breadcrumbs look like, breadcrumbs.html:
And this is directly, breadcrumbs-items.html:
Reviews
(0)