Giter VIP home page Giter VIP logo

django-menu's Introduction

django-menu

BSD-licensed menu tools for Django, built by Ross Poulton <http://www.rossp.org>

django-menu provides a basic structure for you to build multiple navigation menus for your website, such as the header menubar. These menus can be easily maintained by staff using the Django administration without any knowledge of HTML or Django internals.

Sub-menus can also be easily built and displayed only for particular URIs.

Installation & Configuration:

  1. pip install django-menu

  2. Add menu to your INSTALLED_APPS

  3. ./manage.py migrate menu (or ./manage.py syncdb if you don't use South. You should use South.)

  4. Add django.core.context_processors.request to your TEMPLATE_CONTEXT_PROCESSORS. It is not there by default. The default TEMPLATE_CONTEXT_PROCESSORS are::

    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.static",
    "django.contrib.messages.context_processors.messages"
    
  5. Add a Menu (eg called headernavigation) and add some items to that menu

  6. In your template, load the menu tags and embed your primary menu.::

    <ul>{% load menubuilder %}{% menu headernavigation %}
        {% for item in menuitems %}<li><a href="{{ item.url }}" title="{{ item.title|escape }}"{% if item.current %} class='current'{% endif %}>{{ item.title }}</a></li>
        {% endfor %}
    </ul>
    

Submenus:

If your template has a spot for navigation for the current sub-level of your website tree (i.e. a dozen pages underneath /about/, plus a few under /products/) you can create a new menu with a URI of /about/.

In your template, instead of the {% menu %} tag use {% submenu %}. If a submenu for the current URI exists, it will be shown. The {{ submenu_items }} list contains your navigation items, ready to output like in the examples above.

Caching:

To avoid hitting the database every time a user requests a page, the menu items are cached if you have a cache configured. Caching is not used when settings.DEBUG is True.

To disable caching, set the setting MENU_CACHE_TIME to -1 or remove your Django Cache configuration.

To enable caching to continue to let you make items available to anonymous or authenticated users, and to enable the "Current Page" functionality, the cache will contain one dataset for each menu, authentication & path combination.

django-menu's People

Contributors

9nix00 avatar aadidenko avatar brobin avatar johanovic avatar jscissr avatar rossp avatar simon-ccoms avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.