Skip to main content
https://drone.io/bitbucket.org/slafs/django-url-breadcrumbs/status.png

An app for generic breadcrumbs in Django (>= 1.4).

The idea is to make breadcrumbs out of parts of an url path. This application assumes that your url patterns are well structured. For example like this:

/                                               # root path
/application/                                   # root of an app/module
/application/object_type/                       # list of specific objects
/application/object_type/some_object/           # details of specific object
/application/object_type/some_object/edit/      # edit (or any other operations) of a specific object

Installation

  1. Install the package from PyPi. For example via pip:

    pip install django-url-breadcrumbs
  2. Add urlbreadcrumbs to INSTALLED_APPS:

    INSTALLED_APPS = (
        ...
        'urlbreadcrumbs',
        ...
    )
  3. Make sure you have a request context processor django.core.context_processors.request in your TEMPLATE_CONTEXT_PROCESSORS.

Usage

Let’s assume you have your urls in a form:

in ROOT_URLCONF:

from django.conf.urls import patterns, include, url
from myproject.views import some_view

urlpatterns = patterns('',
    url(r'^$', some_view, {'template' : 'index.html'}, name='index'),
    url(r'^test1/', include('test1.urls')),
)

urls.py in application called test1:

from django.conf.urls import patterns, include, url
from test1.views import some_view

urlpatterns = patterns('',
    url(r'^example/$', some_view, {'template' : 't1.html'}, name='t1home'),
)

In order to define your breadcrumbs you can make a mapping in settings.py like this:

URLBREADCRUMBS_NAME_MAPPING = {
    'index'  : 'Home page',
    't1home' : 'Index page of Test1',
}

Then somwhere in your base template (lets call it base.html) you can write this:

{% load urlbreadcrumbs_tags %}
{% render_breadcrumbs %}

or you can specify your own template:

{% render_breadcrumbs "test1/mybreadcrumbs_template.html" %}

Also you can just include your breadcrumbs template:

{% include "test1/mybreadcrumbs_template.html" %}

But to use it like this make sure you’ve added a context procesor urlbreadcrumbs.context_processors.build_breadcrumbs in your TEMPLATE_CONTEXT_PROCESSORS setting.

In your template you have one additional context variable called breadcrumbs which is a list of two-tuples containing name and url of a breadcrumb. The default template used by django-url-breadcrumbs (urlbreadcrumbs/default.html) looks like this:

{% for n,u in breadcrumbs %}
    {% if not forloop.last %}
        <a href="{{ u }}">{{ n }}</a> &raquo;
    {% else %}
        {{ n }}
    {% endif %}
{% endfor %}

So now, assuming template t1.html is extending base.html, when viewing /test1/example/ you should see something like this Home page » Index page of Test1.

Another way of specyfing a name for a breadcrumb is to use a custom url function in your urls.py. Instead of defining a mapping in URLBREADCRUMBS_NAME_MAPPING setting you can do this in urls.py of your ROOT_URLCONF and test1 application:

from django.conf.urls import patterns, include, url
from urlbreadcrumbs import url as burl

urlpatterns = patterns('',
    ...
    burl(r'^test1/', include(test1_urls)),
    ...
)

and

from django.conf.urls import patterns, include, url
from test1.views import some_view
from urlbreadcrumbs import url as burl

urlpatterns = patterns('',
    burl(r'^example/$', some_view, {'template' : 't1.html'}, name='t1home', verbose_name='Index page of Test1'),
)

This should work as in previous example.

Development

Ideas and/or bug reports are welcome. Consider reporting an issue on https://bitbucket.org/slafs/django-url-breadcrumbs/issues?status=new&status=open

Pull requests are also welcome ;).

To start working on this app get the source from Bitbucket:

hg clone https://bitbucket.org/slafs/django-url-breadcrumbs

and in a newly created virtualenv do this:

pip install -r dev_requirements.txt
python setup.py test

Testing

django-url-breadcrumbs uses pytest for running it’s test suite and tox for checking it’s compatibilty with different Python and Django versions.

In order to perform tests with your current python and django installation do this:

python setup.py test

To test it with different python and django versions run this:

tox

Metadata

Release files for django-url-breadcrumbs 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-url-breadcrumbs 0.3.3
File Size Uploaded Provenance
django-url-breadcrumbs-0.3.3.tar.gz 7.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-url-breadcrumbs 0.3.3
File Interpreter ABI Platform
django_url_breadcrumbs-0.3.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 20.2 kB

Release files / django-url-breadcrumbs-0.3.3.tar.gz

Download URL django-url-breadcrumbs-0.3.3.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b66bc852a0a463a93dc983626b4ea9182bd00d47b40ed08ee9cfbc90c8cd73d0
BLAKE2b-256 checksum
How to use checksums
e5366a69a4db893eb91f5882d8a4b1027d7305a885ecacde1ec28017f73f5aae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_url_breadcrumbs-0.3.3-py2.py3-none-any.whl

Download URL django_url_breadcrumbs-0.3.3-py2.py3-none-any.whl
Size 12.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
920a89d6b4f47878473aa834f6e0ae5e8b9d18b1a4cdc8d545bfd0157a5d4889
BLAKE2b-256 checksum
How to use checksums
1e02529661d988af3a979a3c4f9d831a08f0ab199cd94314373be228537292eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-url-breadcrumbs 0.3.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page