How To Add Blog Category Navbar Links - Django Blog #15

preview_player
Показать описание
In this video I'll show you how to add a dropdown menu to the navbar with links to our Category Pages.

We'll use the Bootstrap Navbar code to create a dropdown menu with links to each of our Category pages. We'll also create a webpage with nothing but links to all of our category pages.
Рекомендации по теме
Комментарии
Автор

There is a trick with context_proccessors in django.
For this case just add context_proccessors.py file in the app directory. Inside write something like:

from .models import Category


def navbar_context(request):
return {'cat_menu': Category.objects.all(), }

And don't forget to add this proccessor do settings.py :
TEMPLATES = [
{
...
'OPTIONS': {
'context_processors': [
...


],
...
That will pass 'cat_menu' value to every view (or any other value that you will write inside navbar_context dict).

Nice django blog course btw, found a lot of cool django features for myself!

groovyx
Автор

▶️ Watch Entire Django Blog Playlist ✅ Subscribe To My YouTube Channel:
▶️ See More At: ✅ Join My Facebook Group:

Codemycom
Автор

Very nice vedio, thanks

the reason i am leaving comments on every vedio is beacause 1 day i decided that i am going to leave a comment on every vedio i watch also this was a very good vedio.

shawnbeans
Автор

Is there any specific reason to do so? Because I faced some issues after slugifying from the previous video where after restarting the server, it would give me "the page does not exist" thing after navigating to an existing category.

zubin
Автор

The category main page doesn't show the category nav item, how can I fix that?

silaskanku
Автор

John...this is the first time I see that you are not leaving this halfway through and requesting viewers to pay for the rest of the series...Great... would really appreciate to see this entire series till completion👍... Appreciate if you could also release the source code 😁

codedjango
Автор

Thank you very much for this, as a poor person like my self who just want to learn and maybe get a job this is a blessing.

spreadhysteria
Автор

I want to put the navbar category in the category.html, but I can't figure it out.

spreadhysteria
Автор

I have a little problem

I made this code but when I go to the category the nav dropdown list don't appear

class
model = Post
template_name = 'article_details.html'

def get_context_data(self, *args, **kwargs):
cat_menu = Category.objects.all()
context = super(ArticleDetailView, self).get_context_data(*args, **kwargs)
context["cat_menu"] = cat_menu
return context

marcelotedescodemiranda
Автор

Now still if we add a new category, we have to restart the server
How do we fix that Sir?

ali_sadrian
Автор

How to display category nav in editprofilepage and showprofile page?

silaskanku
Автор

I find every solutions of problems that confused me. Thank you man, I am from Mongolia.

zoljargalenkhtaivan
Автор

cat_menu query set is not formed in my page i exactly followed you whats tht issue

nikithashekhar
Автор

just add a category type in Caps lock on, but it doesnt shows any posts under that

jayashanfernando
Автор

I'm getting this error. Reverse for 'category' with keyword arguments '{'cats': ''}' not found. 1 pattern(s) tried:

md.tanvirfoysal
Автор

How to use cat_menu dropdown menu in each category

raviv
Автор

i have created the def get_context_data function exactly as it is and when i try to pass in {{cat_menu }} in my homepage it doesnot show up

antonyjohn
Автор

I tried for two hours to get this to work; the button shows up on the navbar but does not show the pulldown content... :(

joeyrayhall
Автор

Is there any other solution for not repeating that code for listing category items in navbar?

jameskulu
Автор

hi john! great tuts, thanks for your efforts. I would like to ask how to add number of posts per category. i tried it using annotate but it doesnt work.

jarvismillan