Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 969991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:43:57+00:00 2026-05-16T02:43:57+00:00

I want to use an app to create a menu that is easy to

  • 0

I want to use an app to create a menu that is easy to edit with the admin interface. Something like this:

class Menu_item
        name = models.CharField()
        item_url = models.URLField()

My template looks something like this:

{% extends base.html %}

div ID="nav"

   {{ foo.navbar.? }}

/div

div ID="Content"

   {% block content %}{% endblock %}

/div

I want div#nav to contain a ul based upon the above model but just can’t figure out how to accomplish this. It seems like an object_list generic view would be great but, the URL accesses the view for the model that populates div#content. Does anyone have any suggestions? Is there a way to access a generic view without a URL?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:43:58+00:00Added an answer on May 16, 2026 at 2:43 am

    I have discovered a solution. Inclusion Tags.

    What I did was create an inclusion tag, which amounts to a simple custom template tag (django provides a shortcut for you!).

    Here is what I did:

  2. Ignore views.py – It will not be used in this case
  3. Create a sub-directory in the app’s dir called “templatetags” containing init.py and get_navbar.py (or whatever you want your tag to be):
  4. mysite/
       navbar/
            templatetags/
                __ init__.py (without the space befire init)
                get_navbar.py
    
  5. I changed my navbar.models to look like this:
  6. from django.db import models
    
    
    class Menu_choice(models.Model):
            name = models.CharField(max_length=30)
    
            def __unicode__(self):
                    return self.name
    
    class Menu_item(models.Model):
            name = models.CharField(max_length=20)
            navbar = models.ForeignKey(Menu_choice)
            item_url = models.CharField(max_length=200)
            item_desc = models.CharField(max_length=30)
    
            def __unicode__(self):
                    return self.name
    

    This allows me to create a Menu_choice object in the admin interface for each layer of navigation (primary, secondary, etc)

  7. get_navbar.py looks like this:
  8. from navbar.models import Menu_choice, Menu_item
    from django import template
    
    register = template.Library()
    
    @register.inclusion_tag('navbar/navbar.html')
    def get_navbar(navBar):
            navbar = Menu_item.objects.filter(navbar__name=navBar)
            return { "navbar": navbar }
    

    (Note navBar as opposed to navbar)

  9. Create the navbar.html template:
        <ul>
    {% for menu_item in navbar %} <li><a href="{{ menu_item.item_url }}">{{ menu_item.name }}&lt/a>&lt/li> {% endfor %} </ul>
  10. Finally, I inserted the following into my base.html:
    {% load get_navbar %}
  11. And where I want primary navigation:

    {% get_navbar "primary" %}

    Note: the quotes around the string you are sending to your inclusion tag are important. I spent a ridiculously lengthy bit of time trying to make it work before I figured that out.

    Also a big thank you to dikamilo for the help.

  • 0
  • Reply
  • Share
    Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp
    • Report

Sidebar

Related Questions

I want to create a web app that will use wicket, hibernate and spring
I want to use many bars like this one in my app (i don't
I created a console app that I want to use in a scheduled package
I want to use push notification in my app.i want to know that do
I have an express app that I want to use the connect-form module on
I want to create a component that will appear as a navigation menu for
I want to build an app that use in the backend Ruby on Rails.
I want to create a Django Admin Action that allows me to create a
I want to use session object in my web app.I want to store some
I want to use mysql with a rails app (I have never used mysql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.