Create navbar dropdown menu list with url tags

194 views
Skip to first unread message

pythonc...@gmail.com

unread,
Jul 6, 2016, 10:27:41 AM7/6/16
to Django users
Hi,
I have a model and whould like to create a dropdown menu from the fields generated.
Unfortunately no dropdown list is showed:
 <ul class="dropdown-menu" >
                 {% for airline in alirlines %}

                <li><a href="/airline_detail/{{airline.code}}">{{ airline.airline }}</a></li>
               {% endfor %}
              
              </ul>

this is the model:
class Airline(models.Model):
     airline = models.CharField(max_length=50)
     prefix = models.CharField(max_length=3)
     code= models.CharField(max_length=3)
     ticker = models.CharField(max_length=1)


can anyone help? thanks

ludovic coues

unread,
Jul 6, 2016, 3:20:31 PM7/6/16
to django...@googlegroups.com
try to add that
## {{ airlines|pprint }}

If it show `## ''` in the page, airlines is not defined in the template context.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/939a1bd5-433b-4c89-9c6c-4b51a22eaf48%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

pythonc...@gmail.com

unread,
Jul 7, 2016, 11:31:53 AM7/7/16
to Django users
Drop down menu still not showing... Forgot to say navbar.html is inherited in base.html.
I created a view
.def navbar(request):
   
  
    airlines= Airline.objects.all()
    template = 'navbar.html'
    context = {
      
        'airlines': airlines,
    }

    return render(request, template, {})

ludovic coues

unread,
Jul 7, 2016, 11:40:13 AM7/7/16
to django...@googlegroups.com
"## {{ airlines|pprint }}" can't display a dropdown menu.
It's a debug tool.
It's supposed to show two # symbol so you know you are editing the
right template then it should display a python representation of what
airlines is.
If things work as expected, you should have something like that in the page:
## [<airline object>, <airline object>, <airline object>]
If airlines is an empty list, you will get that:
## []
If airlines is not defined, you will get that:
## ''
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5261e7bd-3a2a-4f7f-917e-8c8f2879db52%40googlegroups.com.

Prog Nauts

unread,
Jul 12, 2016, 10:24:20 AM7/12/16
to Django users
ok clear


Il giorno mercoledì 6 luglio 2016 16:27:41 UTC+2, pythonc...@gmail.com ha scritto:
Reply all
Reply to author
Forward
0 new messages