How to manage a dynamic menu with Django?












0















I would like to create the links of the menu dynamically based on the Category models. I've used DetailView and ListView for create a list and detail page of a single category and it run fine.



Now I would like to see in base.html a new link in a "dropdown" menu every time the user add a new Category.



This is base.html



{% load static %}

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<title>{% block head_title %}Test{% endblock head_title %}</title>
</head>
<body>


<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'list_tag' %}">Tag</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Category
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
{% for category in category_list %}
<a href="{{ category.get_absolute_url }}">{{ category.category_name }}</a>
{% endfor %}
</div>
</li>
</div>
</nav>


<div class="container">
<!-- INIZIO corpo centrale -->
{% block content %}

{% endblock content %}
<!-- FINE corpo centrale -->
</div>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>


This is list_category.html



{% extends 'base.html' %}

{% load static %}

{% block head_title %}Elenco Categorie | {{ block.super }}{% endblock head_title %}

{% block content %}


{% for category in category_list %}
<h1><a href="{{ category.get_absolute_url }}">{{ category.category_name }}</a></h1>
<hr>
{% endfor %}


{% endblock content %}


This is views.py



class CategoryList(ListView):
model = Category
context_object_name = 'category_list'
template_name = "list_category.html"


class SingleCategory(DetailView):
model = Category
template_name = "single_category.html"


When I use the code in base.html it was shown an empty menu.
How I can resolve?




UPDATE:




Using the solution of @ans2human in this post, I've created a file context_processors.py like below:



from .models import Category

def blog_menu(request):

link_menu = Category.objects.all()
return {
'link_menu': link_menu
}


Then I've added the string in settings.py:



'blog.context_processors.blog_menu',


The new strings of dropdown menu are these:



<li class="nav-item active dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="far fa-newspaper" id="img"></i> Blog
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#"></i> {{ link_menu }}</a>
</div>
</li>


Now I've this situation in the menu enter image description here



It seems that work but not correctly. How I can resolve?










share|improve this question

























  • In views missing queryset

    – Pranay reddy
    Nov 13 '18 at 11:43











  • agiliq.com/blog/2017/12/when-and-how-use-django-listview

    – Pranay reddy
    Nov 13 '18 at 11:45











  • The presence or the missing of the queryset isn't the problem. I've added the queryset but nothing is changed

    – Massimiliano Moraca
    Nov 13 '18 at 17:07
















0















I would like to create the links of the menu dynamically based on the Category models. I've used DetailView and ListView for create a list and detail page of a single category and it run fine.



Now I would like to see in base.html a new link in a "dropdown" menu every time the user add a new Category.



This is base.html



{% load static %}

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<title>{% block head_title %}Test{% endblock head_title %}</title>
</head>
<body>


<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'list_tag' %}">Tag</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Category
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
{% for category in category_list %}
<a href="{{ category.get_absolute_url }}">{{ category.category_name }}</a>
{% endfor %}
</div>
</li>
</div>
</nav>


<div class="container">
<!-- INIZIO corpo centrale -->
{% block content %}

{% endblock content %}
<!-- FINE corpo centrale -->
</div>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>


This is list_category.html



{% extends 'base.html' %}

{% load static %}

{% block head_title %}Elenco Categorie | {{ block.super }}{% endblock head_title %}

{% block content %}


{% for category in category_list %}
<h1><a href="{{ category.get_absolute_url }}">{{ category.category_name }}</a></h1>
<hr>
{% endfor %}


{% endblock content %}


This is views.py



class CategoryList(ListView):
model = Category
context_object_name = 'category_list'
template_name = "list_category.html"


class SingleCategory(DetailView):
model = Category
template_name = "single_category.html"


When I use the code in base.html it was shown an empty menu.
How I can resolve?




UPDATE:




Using the solution of @ans2human in this post, I've created a file context_processors.py like below:



from .models import Category

def blog_menu(request):

link_menu = Category.objects.all()
return {
'link_menu': link_menu
}


Then I've added the string in settings.py:



'blog.context_processors.blog_menu',


The new strings of dropdown menu are these:



<li class="nav-item active dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="far fa-newspaper" id="img"></i> Blog
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#"></i> {{ link_menu }}</a>
</div>
</li>


Now I've this situation in the menu enter image description here



It seems that work but not correctly. How I can resolve?










share|improve this question

























  • In views missing queryset

    – Pranay reddy
    Nov 13 '18 at 11:43











  • agiliq.com/blog/2017/12/when-and-how-use-django-listview

    – Pranay reddy
    Nov 13 '18 at 11:45











  • The presence or the missing of the queryset isn't the problem. I've added the queryset but nothing is changed

    – Massimiliano Moraca
    Nov 13 '18 at 17:07














0












0








0








I would like to create the links of the menu dynamically based on the Category models. I've used DetailView and ListView for create a list and detail page of a single category and it run fine.



Now I would like to see in base.html a new link in a "dropdown" menu every time the user add a new Category.



This is base.html



{% load static %}

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<title>{% block head_title %}Test{% endblock head_title %}</title>
</head>
<body>


<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'list_tag' %}">Tag</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Category
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
{% for category in category_list %}
<a href="{{ category.get_absolute_url }}">{{ category.category_name }}</a>
{% endfor %}
</div>
</li>
</div>
</nav>


<div class="container">
<!-- INIZIO corpo centrale -->
{% block content %}

{% endblock content %}
<!-- FINE corpo centrale -->
</div>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>


This is list_category.html



{% extends 'base.html' %}

{% load static %}

{% block head_title %}Elenco Categorie | {{ block.super }}{% endblock head_title %}

{% block content %}


{% for category in category_list %}
<h1><a href="{{ category.get_absolute_url }}">{{ category.category_name }}</a></h1>
<hr>
{% endfor %}


{% endblock content %}


This is views.py



class CategoryList(ListView):
model = Category
context_object_name = 'category_list'
template_name = "list_category.html"


class SingleCategory(DetailView):
model = Category
template_name = "single_category.html"


When I use the code in base.html it was shown an empty menu.
How I can resolve?




UPDATE:




Using the solution of @ans2human in this post, I've created a file context_processors.py like below:



from .models import Category

def blog_menu(request):

link_menu = Category.objects.all()
return {
'link_menu': link_menu
}


Then I've added the string in settings.py:



'blog.context_processors.blog_menu',


The new strings of dropdown menu are these:



<li class="nav-item active dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="far fa-newspaper" id="img"></i> Blog
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#"></i> {{ link_menu }}</a>
</div>
</li>


Now I've this situation in the menu enter image description here



It seems that work but not correctly. How I can resolve?










share|improve this question
















I would like to create the links of the menu dynamically based on the Category models. I've used DetailView and ListView for create a list and detail page of a single category and it run fine.



Now I would like to see in base.html a new link in a "dropdown" menu every time the user add a new Category.



This is base.html



{% load static %}

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<title>{% block head_title %}Test{% endblock head_title %}</title>
</head>
<body>


<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'list_tag' %}">Tag</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Category
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
{% for category in category_list %}
<a href="{{ category.get_absolute_url }}">{{ category.category_name }}</a>
{% endfor %}
</div>
</li>
</div>
</nav>


<div class="container">
<!-- INIZIO corpo centrale -->
{% block content %}

{% endblock content %}
<!-- FINE corpo centrale -->
</div>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>


This is list_category.html



{% extends 'base.html' %}

{% load static %}

{% block head_title %}Elenco Categorie | {{ block.super }}{% endblock head_title %}

{% block content %}


{% for category in category_list %}
<h1><a href="{{ category.get_absolute_url }}">{{ category.category_name }}</a></h1>
<hr>
{% endfor %}


{% endblock content %}


This is views.py



class CategoryList(ListView):
model = Category
context_object_name = 'category_list'
template_name = "list_category.html"


class SingleCategory(DetailView):
model = Category
template_name = "single_category.html"


When I use the code in base.html it was shown an empty menu.
How I can resolve?




UPDATE:




Using the solution of @ans2human in this post, I've created a file context_processors.py like below:



from .models import Category

def blog_menu(request):

link_menu = Category.objects.all()
return {
'link_menu': link_menu
}


Then I've added the string in settings.py:



'blog.context_processors.blog_menu',


The new strings of dropdown menu are these:



<li class="nav-item active dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="far fa-newspaper" id="img"></i> Blog
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#"></i> {{ link_menu }}</a>
</div>
</li>


Now I've this situation in the menu enter image description here



It seems that work but not correctly. How I can resolve?







html django django-templates django-views django-2.1






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 7:42







Massimiliano Moraca

















asked Nov 13 '18 at 10:06









Massimiliano MoracaMassimiliano Moraca

819




819













  • In views missing queryset

    – Pranay reddy
    Nov 13 '18 at 11:43











  • agiliq.com/blog/2017/12/when-and-how-use-django-listview

    – Pranay reddy
    Nov 13 '18 at 11:45











  • The presence or the missing of the queryset isn't the problem. I've added the queryset but nothing is changed

    – Massimiliano Moraca
    Nov 13 '18 at 17:07



















  • In views missing queryset

    – Pranay reddy
    Nov 13 '18 at 11:43











  • agiliq.com/blog/2017/12/when-and-how-use-django-listview

    – Pranay reddy
    Nov 13 '18 at 11:45











  • The presence or the missing of the queryset isn't the problem. I've added the queryset but nothing is changed

    – Massimiliano Moraca
    Nov 13 '18 at 17:07

















In views missing queryset

– Pranay reddy
Nov 13 '18 at 11:43





In views missing queryset

– Pranay reddy
Nov 13 '18 at 11:43













agiliq.com/blog/2017/12/when-and-how-use-django-listview

– Pranay reddy
Nov 13 '18 at 11:45





agiliq.com/blog/2017/12/when-and-how-use-django-listview

– Pranay reddy
Nov 13 '18 at 11:45













The presence or the missing of the queryset isn't the problem. I've added the queryset but nothing is changed

– Massimiliano Moraca
Nov 13 '18 at 17:07





The presence or the missing of the queryset isn't the problem. I've added the queryset but nothing is changed

– Massimiliano Moraca
Nov 13 '18 at 17:07












1 Answer
1






active

oldest

votes


















1















UPDATE 2




Good news!
Since I'm not a django expert, I had a trivial difficulty. By reasoning a little more, I found the solution.



Below the solution:



    <div class="dropdown-menu" aria-labelledby="navbarDropdown">
{% for link in link_menu %}
<a class="dropdown-item" href="{{ link.get_absolute_url }}"> {{ link.category_name }}</a>
{% endfor %}
</div>





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278506%2fhow-to-manage-a-dynamic-menu-with-django%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1















    UPDATE 2




    Good news!
    Since I'm not a django expert, I had a trivial difficulty. By reasoning a little more, I found the solution.



    Below the solution:



        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
    {% for link in link_menu %}
    <a class="dropdown-item" href="{{ link.get_absolute_url }}"> {{ link.category_name }}</a>
    {% endfor %}
    </div>





    share|improve this answer




























      1















      UPDATE 2




      Good news!
      Since I'm not a django expert, I had a trivial difficulty. By reasoning a little more, I found the solution.



      Below the solution:



          <div class="dropdown-menu" aria-labelledby="navbarDropdown">
      {% for link in link_menu %}
      <a class="dropdown-item" href="{{ link.get_absolute_url }}"> {{ link.category_name }}</a>
      {% endfor %}
      </div>





      share|improve this answer


























        1












        1








        1








        UPDATE 2




        Good news!
        Since I'm not a django expert, I had a trivial difficulty. By reasoning a little more, I found the solution.



        Below the solution:



            <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        {% for link in link_menu %}
        <a class="dropdown-item" href="{{ link.get_absolute_url }}"> {{ link.category_name }}</a>
        {% endfor %}
        </div>





        share|improve this answer














        UPDATE 2




        Good news!
        Since I'm not a django expert, I had a trivial difficulty. By reasoning a little more, I found the solution.



        Below the solution:



            <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        {% for link in link_menu %}
        <a class="dropdown-item" href="{{ link.get_absolute_url }}"> {{ link.category_name }}</a>
        {% endfor %}
        </div>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 7:42









        Massimiliano MoracaMassimiliano Moraca

        819




        819
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278506%2fhow-to-manage-a-dynamic-menu-with-django%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            List item for chat from Array inside array React Native

            Thiostrepton

            Caerphilly