How to implement breadcrumbs in a Django template?

前端 未结 12 2061
無奈伤痛
無奈伤痛 2020-12-07 09:45

Some solutions provided on doing a Google search for \"Django breadcrumbs\" include using templates and block.super, basically just extending the base blocks and adding the

12条回答
  •  时光取名叫无心
    2020-12-07 10:12

    Obviously, no one best answer, but for practical reason I find that it is worth considering the naïve way. Just overwrite and rewrite the whole breadcrumb... (at least until the official django.contrib.breadcrumb released )

    Without being too fancy, it is better to keep things simple. It helps the newcomer to understand. It is extremely customizable (e.g. permission checking, breadcrumb icon, separator characters, active breadcrumb, etc...)

    Base Template

    
    
    
      {% block breadcrumb %}
      
      {% endblock breadcrumb %}
      {% block content %}{% endblock content %}
    
    
    

    Implementation Template

    Later on each pages we rewrite and overwrite the whole breadcrumb block.

    
    {% extends 'base.html' %}
    {% block breadcrumb %}
    
    {% endblock breadcrumb %}
    

    Practicallity

    Realworld use cases:

    • Django Oscar: base template, simple bread
    • Django Admin: base template, simple bread, permission check breadcrumb

提交回复
热议问题