GithubHelp home page GithubHelp 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.template.context_processors.request to your TEMPLATE settings. Below is a reasonably safe TEMPLATES setting for most small projects, however yours may vary.:

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [os.path.join(BASE_DIR, 'templates')],
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [
                    'django.template.context_processors.debug',
                    'django.template.context_processors.request',
                    'django.contrib.auth.context_processors.auth',
                    'django.contrib.messages.context_processors.messages',
                    'django.template.context_processors.request',
                ],
            },
        },
    ]
  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 bashu avatar brobin avatar johanovic avatar jscissr avatar rc9000 avatar rossp avatar simon-ccoms avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

django-menu's Issues

Menu matching query does not exist

Do you have this working in django 1.4 or another version? It seems to work fine for me in the admin. It looks like the perfect app for my needs, but my pages no longer load once I load the template tag as noted in the documentation. I get an error "Menu matching query does not exist."

I'm pretty new to django. I'm using django 1.4 and python2.7, so I was just wondering if it could be a version problem. - thanks

Warning with `TEMPLATE_CONTEXT_PROCESSORS` and Django 1.11

When I set TEMPLATE_CONTEXT_PROCESSORS in the settings.py, I got a warning from Django:

WARNINGS:
?: (1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 and the TEMPLATES dictionary takes precedence. You must put the values of the following settings into your default TEMPLATES dict: TEMPLATE_CONTEXT_PROCESSORS

django-menu key error

whether the django-menu version of Django 1.5?

TEMPLATE_CONTEXT_PROCESSORS
('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.core.context_processors.tz',
  'django.contrib.messages.context_processors.messages',
  'django.core.context_processors.request')

{% Block content%}

         {% Load menubuilder%}

         {% Menu main_menu%}

         {% For item in menuitems%}
             {{Item.title}}
         {% Endfor%}
         </ ul>
    {% Endblock%}

    Error:
     
    KeyError at / blog /
    'request'
    Request Method:
    GET
    Request URL:
    http://127.0.0.1:8080/blog/
    Django Version:
    1.5.1
    Exception Type:
    KeyError
    Exception Value:
    'request'
    Exception Location:
    C: \ Python27 \ lib \ site-packages \ django \ template \ context.py in __ getitem__, line 57
    Python Executable:
    C: \ Python27 \ python.exe
    Python Version:
    2.7.3

    whi? Please HELP ME

invalid syntax (menubuilder.py, line 14)

Help me please ...

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/menu/

Django Version: 1.5.3
Python Version: 3.3.0
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'testDjangoproject.first_project',
'menu')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')

Traceback:
File "C:\Python33\Lib\site-packages\django\core\handlers\base.py" in get_response

  1.                     response = callback(request, _callback_args, *_callback_kwargs)
    
    File "C:\Documents and Settings\Admin\PycharmProjects\testDjangoproject\testDjangoproject\first_project\views.py" in my_menu
  2. return render_to_response('base.html')
    
    File "C:\Python33\Lib\site-packages\django\shortcuts__init__.py" in render_to_response
  3. return HttpResponse(loader.render_to_string(_args, *_kwargs), **httpresponse_kwargs)
    
    File "C:\Python33\Lib\site-packages\django\template\loader.py" in render_to_string
  4.     t = get_template(template_name)
    
    File "C:\Python33\Lib\site-packages\django\template\loader.py" in get_template
  5. template, origin = find_template(template_name)
    
    File "C:\Python33\Lib\site-packages\django\template\loader.py" in find_template
  6.         source, display_name = loader(name, dirs)
    
    File "C:\Python33\Lib\site-packages\django\template\loader.py" in call
  7.     return self.load_template(template_name, template_dirs)
    
    File "C:\Python33\Lib\site-packages\django\template\loader.py" in load_template
  8.         template = get_template_from_string(source, origin, template_name)
    
    File "C:\Python33\Lib\site-packages\django\template\loader.py" in get_template_from_string
  9. return Template(source, origin, name)
    
    File "C:\Python33\Lib\site-packages\django\template\base.py" in init
  10.     self.nodelist = compile_string(template_string, origin)
    
    File "C:\Python33\Lib\site-packages\django\template\base.py" in compile_string
  11. return parser.parse()
    
    File "C:\Python33\Lib\site-packages\django\template\base.py" in parse
  12.                 compiled_result = compile_func(self, token)
    
    File "C:\Python33\Lib\site-packages\django\template\defaulttags.py" in load
  13.             lib = get_library(taglib)
    
    File "C:\Python33\Lib\site-packages\django\template\base.py" in get_library
  14.         lib = import_library(taglib_module)
    
    File "C:\Python33\Lib\site-packages\django\template\base.py" in import_library
  15.     mod = import_module(taglib_module)
    
    File "C:\Python33\Lib\site-packages\django\utils\importlib.py" in import_module
  16. **import**(name)
    

Exception Type: SyntaxError at /menu/
Exception Value: invalid syntax (menubuilder.py, line 14)

Problem sub menu not showing

Hello there, i was using this django-menu for my project, but we have some problem if we need to show sub-menu item.
Now we use django 1.8.5

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

I was try wollowing tutorial from: https://www.rossp.org/blog/menus/, but not showing...

{% load menubuilder %}
{% submenu %}
{% if submenu %}
  {{ submenu.name }}
  {% for item in submenu_items %}
    {{ item.title }}
  {% endfor %}
{% endif %}

Error in Django 1.10 south

Hi i use Django 1.10.x when install i see the error
from south.db import db
ImportError: No module named south.db

i know i need install south but why Django core have migration app, i think need update
the code for use in Django 1.7+ this version no need anymore south.

Thank

needs RequestContext

It would not display with several of my forms. I had to use RequestContext in the views add django.core.context_processors.request to my TEMPLATE_CONTEXT_PROCESSORS variable in settings.py for it to work as desired.
I might have overlooked this in the docs. If so, forget this issue, if not, add this remark to the docs, please.
wC

Please release 0.1.10

Hey I installed django-menu from the latest sources and it fixes the warnings I am getting about BooleanField default changes. Could you please release the current version (version # set to 0.1.10) to pypi so I don't have to install from the GitHub tarball?

Thanks in advance,

feature discuss: about menu model with site

should we add site(django site model) foreign key for Menu model?

I think it's useful if we maintain many site in same database.

if you think it's. I can post a PR for this feature.

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.