简体   繁体   中英

Simple static breadcrumb in Django

How to create something like this:

If user is in: http://127.0.0.1:8000/about/ then in my base.html I have:

You are here: <li><a href="/about/">Home</a></li>

Etc.

Is there a simple way?

This can get tricky, depending on what you mean by "breadcrumbs".

  1. Django's URL routing system has no inherent hierarchy since any URL can map to any view.
  2. So the "hierarchy" has to be completely specified by you.
  3. …and passed by you to the template in either your view, or in a context processor.
  4. You'll want to assign both a URL AND a name for the URL (so you know /about/ is "Home").

There are a bajillion ways to do this, and it all sort of depends on how flexible you want it, how complicated your URL patterns get, whether you want to support nesting, etc.

Normally, I just use Django Breadcrumbs . This project handles all of the weirdness of breadcrumbs, has a very easy to use API, and handles even weird cases.

While a full code sample would probably be helpful, it's a long and thorny problem, so you're better off reading the documentation for django-breadcrumbs, and then returning here with questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM