Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Easy to use generic breadcrumbs system for Django framework.

branch: breadcrumbs_app

This branch is 0 commits ahead and 48 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.markdown

django-breadcrumbs is a breadcrumb system to Django framework that allow you to add custom breadcrumbs for simple views, generic views and support Django FlatPages app.

In format of a pluggable middleware that add a breadcrumbs callable/iterable in your request object, allowing you to set breadcrumbs (one or more) in each view accepting objects, lists or tuples added from request.breadcrumbs and is iterable, easy to use in templates providing a object with name and url attributes.

Note: For Django 1.x, check for tag 1.0 and patches :)

1 - Install django-breadcrumbs

Just put in your python patch and add breadcrumbs.middleware.BreadcrumbsMiddleware to your MIDDLEWARE_CLASSES.

2 - Adding breadcrumbs

To add breadcrumbs you just need to call request.breadcrumbs('Title',url), ex:

def about(request):
    request.breadcrumbs(_("About"),request.path_info)
    ...

def generic_crud_view(request,model,action):
    """
    model = model name
    action = action name
    """

    request.breadcrumbs([
        (_(model.title()),'/crud/%s' % model),
        (_('%s %s') % (action.title(),model.title()),'/crud/%s/%s' % (model,action)),
    ])

    ...

All modes of add a breadcrumb:

# one by one
request.breadcrumbs( name, url )

# various tuples/lists
request.breadcrumbs( ( (name1, url1), (name2, url2), (name3, url3), ...,) )
request.breadcrumbs( [ [name1, url1], [name2, url2], [name3, url3], ...] )

# objects with attributes name and url in list / tuple format:
request.breadcrumbs( ( obj1, obj2, obj3, obj4, ......) )
request.breadcrumbs( [ obj1, obj2, obj3, obj4, ......] )

Note: You can use request.breadcrumbs safely in any middleware after BreadcrumbsMiddleware or any place where you have request object after BreadcrumbsMiddleware are processed

3 - Enable FlatPages + Breadcrumbs

FlatPages is a app that allow user create urls with static content and a title. But create breadcrumbs for this kind of 'unknow' url path isn't fun at all, so I modified FlatpageFallbackMiddleware to fill breadcrumbs for each flat page in path.

Is really easy to use, just add breadcrumbs.middleware.FlatpageFallbackMiddleware in your MIDDLEWARE_CLASSES after BreadcrumbsMiddleware and all done!

4 - Using in templates

To use breadcrumbs in template, only that you need is iterate over breadcrumbs, example:

{% for breadcrumb in request.breadcrumbs %}
<a href="{{ breadcrumb.url }}">{{ breadcrumb.name }}</a>{% if not forloop.last %} >> {% endif %}
{% endfor %}

5 - Options

django-breadcrumbs have a single option to set in your settings.py:

BREADCRUMBS_AUTO_HOME: defaults to False, If True, breadcrumbs add as first Breadcrumb in list (_("Home"),u"/")
Something went wrong with that request. Please try again.