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

  Рет қаралды 23,322

Codemy.com

Codemy.com

Күн бұрын

Пікірлер: 108
@groovyx638
@groovyx638 2 жыл бұрын
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': [ ... '.context_proccessors.navbar_context' ], ... 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!
@rogueDukakis
@rogueDukakis Жыл бұрын
You my friend are a genius. How did you learn to do that?
@Codemycom
@Codemycom 4 жыл бұрын
▶️ Watch Entire Django Blog Playlist ✅ Subscribe To My KZbin Channel: bit.ly/3bWN6wj bit.ly/2IGzvOR ▶️ See More At: ✅ Join My Facebook Group: Codemy.com bit.ly/2GFmOBz ▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt! Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN
@shawnbeans7389
@shawnbeans7389 4 жыл бұрын
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.
@Codemycom
@Codemycom 4 жыл бұрын
Fun
@codedjango
@codedjango 4 жыл бұрын
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 😁
@Codemycom
@Codemycom 4 жыл бұрын
Yeah I'll release the source code eventually...but you don't really need it...it's not all that extensive.
@spreadhysteria3650
@spreadhysteria3650 4 жыл бұрын
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.
@Codemycom
@Codemycom 4 жыл бұрын
Glad you enjoy them :-)
@zubin1677
@zubin1677 4 жыл бұрын
I noticed that you changed the code from the previous video on line 31 (@14:30) of views.py page from cats.title().replace('-'.' ') to cats.replace('-', ' ').title() 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.
@Codemycom
@Codemycom 4 жыл бұрын
Those things aren't related
@zoljargalenkhtaivan9661
@zoljargalenkhtaivan9661 3 жыл бұрын
I find every solutions of problems that confused me. Thank you man, I am from Mongolia.
@azimsonny6036
@azimsonny6036 4 жыл бұрын
was waiting for your updates! :)
@Codemycom
@Codemycom 4 жыл бұрын
More to come! I post django blog videos monday, wednesday, and friday
@silaskanku7377
@silaskanku7377 2 жыл бұрын
The category main page doesn't show the category nav item, how can I fix that?
@spreadhysteria3650
@spreadhysteria3650 4 жыл бұрын
I want to put the navbar category in the category.html, but I can't figure it out.
@ali_sadrian
@ali_sadrian 2 жыл бұрын
Now still if we add a new category, we have to restart the server How do we fix that Sir?
@ZabeelBasheer
@ZabeelBasheer 4 жыл бұрын
Hi John. This is a fantastic series. I was able to follow through most of the instructions until now. I just have clarification here on the dynamic category context data. I understand that we could use a function get_context_data repeated under the classes in views.py. My question is, if we need to use it in a function, for example, CategoryView, how do we merge these two functions?
@Codemycom
@Codemycom 4 жыл бұрын
It's a little tricky...I sort of get into that later in the course
@hanadraskovic6839
@hanadraskovic6839 4 жыл бұрын
Hey, amazing tutorial, thanks! I have the same question, hope it comes up later. I am new to django but not to python. It looks simple but I think my syntax is wrong, or I am missing something. I tried to define the function outside of the classes, add a variable to the function def, one to replace the HomeView as a static but it's not working.... >> get_context_data(self, *args, **kwargs, view): ...super(view, self)
@marcelotedescodemiranda401
@marcelotedescodemiranda401 3 жыл бұрын
I have a little problem I made this code but when I go to the category the nav dropdown list don't appear class ArticleDetailView(DetailView): 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
@rafiatunlubaba4254
@rafiatunlubaba4254 3 жыл бұрын
have you solved it
@silaskanku7377
@silaskanku7377 2 жыл бұрын
How to display category nav in editprofilepage and showprofile page?
@RahulRoy-wo9dg
@RahulRoy-wo9dg 4 жыл бұрын
hi i just want to suggest that we can use templatetags instead of using context, then we have to write a function in the backend once and use it in frontend multiple times...BTW loved your videos...sir u are really awsome
@gamingmobility8734
@gamingmobility8734 2 жыл бұрын
absolutely underrated comment!
@raviv469
@raviv469 4 жыл бұрын
How to use cat_menu dropdown menu in each category
@nikithashekhar1522
@nikithashekhar1522 Жыл бұрын
cat_menu query set is not formed in my page i exactly followed you whats tht issue
@Codemycom
@Codemycom Жыл бұрын
check your code, you think you followed exactly, but you missed something.
@jarvismillan2529
@jarvismillan2529 3 жыл бұрын
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.
@md.tanvirfoysal9942
@md.tanvirfoysal9942 3 жыл бұрын
I'm getting this error. Reverse for 'category' with keyword arguments '{'cats': ''}' not found. 1 pattern(s) tried: ['blog/category/(?P[^/]+)/$']
@anopta
@anopta 3 жыл бұрын
Reverse for 'category'......means that there is no return url for your category. Check this:. Class AddCategoryView should have: fields = '__all__' success_url=reverse_lazy("home")
@apolovzla_ccs
@apolovzla_ccs 4 жыл бұрын
Hello guys. I managed to make the navlink work on every single view and it is really easy, all you have to do is: 1) use this url pattern at the URLconfig file: path('/', CategoryView ,name='category'). As you can see I simplified the url to only use the string part of the category. You have to put this url parameter at the very last position of your urls list, if not, you will receive an error for any address you try to reach, because Django is going to check every url against this pattern if you place it at the very first place of the list. As an example, this is my url list from the url.py file: urlpatterns = [ path('', HomeView.as_view(), name='home'), path('article/', ArticleDetailView.as_view(), name='article_detail'), path('add_post/', AddPostView.as_view(), name='add_post'), path('add_category/', AddCategoryView.as_view(), name='add_category'), path('article/edit/', UpdatePostView.as_view(), name='update_post'), path('article//remove', DeletePostView.as_view(), name='delete_post'), path('conocenos/', TemplateView.as_view(), name='conocenos'), path('identidad/', TemplateView.as_view(), name='identidad'), path('hacemos/', TemplateView.as_view(), name='hacemos'), path('contacto/', TemplateView.as_view(), name='contacto'), path('/', CategoryView ,name='category'), ] Pay attention to the last row. 2) At the navbar, replace this: XXXXXXXX with this: XXXXXXXX where XXXXXXX is the string/name of your category, I'll give an example with a category called Banks: replace this: Banks with this: Banks And that's all. It should do the trick. Right now I am struggling to try to show all the posts from the same category at the ArcticleDetailView. I need to show all the posts from the same category of the opened post, depending on which category it belongs to. For example, if I open a post from the "Banks" category, I need to show all the posts from that category at the bottom of the page, but if later on I open a post from a category called "Clients" I need to retrieve all the posts from that category at the bottom of the page. So, what I need to do is to take the rendered post's category and pass it to the view.py file to render the other posts from the same category in the page. I understand that I have to do it using the get_context_data, but it's not exactly clear for me how to do it. @Codemy.com any idea on how to do it? Hope I helped you guys out, and keep coding, don't give up, keep learning.
@Codemycom
@Codemycom 4 жыл бұрын
cool
@apolovzla_ccs
@apolovzla_ccs 4 жыл бұрын
@@Codemycom Jhon, can you point me to the direction where I can find information on how to capture information from the page? as I said in my comment, how can I capture the post category to show all the other posts fro the samr category at the bottom of ghe page? how can I captura that "variable"?
@spreadhysteria3650
@spreadhysteria3650 4 жыл бұрын
Did you manage to bring the drop-down menu category navbar, in the category.html?
@apolovzla_ccs
@apolovzla_ccs 4 жыл бұрын
@@spreadhysteria3650 I haven't been able to capture the page's category. Actually I bough a book on Amazon to learn more in depth about Django. In WordPress there's an environmental variable that captures things like the post's category but I can't find such thing in Django so i think it needs yo be coded by hand.
@angusgane1979
@angusgane1979 4 жыл бұрын
Is this what you are looking for? Gets a category dropdown menu in categories.html def CategoryView(request, cats): category_posts = Post.objects.filter(category__iexact=cats.replace('-', ' ')) context = {} context['cats'] = cats.title().replace('-', ' ') context['category_posts'] = category_posts cat_menu = Category.objects.all() context['cat_menu'] = cat_menu return render(request, 'categories.html', context)
@jayashanfernando4714
@jayashanfernando4714 2 жыл бұрын
just add a category type in Caps lock on , but it doesnt shows any posts under that
@ffoofooify
@ffoofooify 4 жыл бұрын
You are Amazing and funny from France :) continue
@Codemycom
@Codemycom 4 жыл бұрын
So nice of you to say!
@antonyjohn2163
@antonyjohn2163 4 жыл бұрын
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
@Codemycom
@Codemycom 4 жыл бұрын
Then it's not exactly as it is. You have a typo somewhere
@antonyjohn2163
@antonyjohn2163 4 жыл бұрын
@@Codemycom could you upload a source code on github for the project up until now im getting some no reverse match errors also after i had the ckeditor installed if your could upload the project on github it would be really helpfull we can keep checking our code also , also this is one of the best turtorial i havefound on youtube for django thanks sir.
@Codemycom
@Codemycom 4 жыл бұрын
@@antonyjohn2163 I will sometime, but you'll have to rewatch the videos and retrace your steps in the mean time
@antonyjohn2163
@antonyjohn2163 4 жыл бұрын
@@Codemycom alright sir
@RahulPatil-m
@RahulPatil-m 4 жыл бұрын
@@antonyjohn2163 did you get the solution??
@prahladthelord4668
@prahladthelord4668 4 жыл бұрын
Sir How to make the search function , In django blog to search for blog articles ? If Possible make a video plz
@Codemycom
@Codemycom 4 жыл бұрын
We may look at that
@solomonkassahun7845
@solomonkassahun7845 4 жыл бұрын
damn you are the best thing of 2020 thank you!!!!
@Codemycom
@Codemycom 4 жыл бұрын
Thanks! Though being the best of 2020 is maybe a dubious honor ;-P LOL
@joeyrayhall3142
@joeyrayhall3142 Жыл бұрын
I tried for two hours to get this to work; the button shows up on the navbar but does not show the pulldown content... :(
@Codemycom
@Codemycom Жыл бұрын
what did you do differently from the video?
@jyotirani6238
@jyotirani6238 4 жыл бұрын
One of my category is DIYs. Now if I go to blogcategory/DIYs its working. but clicking on DIYs category from the navbar take me to blogcategory/diys and this page is showing 404 error page (the page I created for the case if the category does not exist). What should i do to solve this problem?
@fatimas6428
@fatimas6428 3 жыл бұрын
I'm facing the same problem... guess we have to add categories in all Small letters...I think the is somehow converting CAPS into small letters and in the CategoryView, it is not able to find a match....i don't know if I'm correct... If someone has some better solution, please do share
@jameskulu
@jameskulu 4 жыл бұрын
Is there any other solution for not repeating that code for listing category items in navbar?
@Codemycom
@Codemycom 4 жыл бұрын
of course, you can do it any way you like...there's always infinite ways to do a thing
@apolovzla_ccs
@apolovzla_ccs 4 жыл бұрын
@@Codemycom What about defining the function at the beginning of the views.py file and call it from inside every class view? the problem is how to pull the class name to add it automatically to the super function contained in the context variable. Where can I find information about that?
@iamnetwork9423
@iamnetwork9423 4 жыл бұрын
Sir, how to capitalize cat_menu_list
@nooobgamer01
@nooobgamer01 4 жыл бұрын
great sir ❤❤
@Codemycom
@Codemycom 4 жыл бұрын
:-)
@mehmetali1945
@mehmetali1945 4 жыл бұрын
does base.html has access to home.html variables we passed like cat_menu , if so is it specifically to home.html ?
@Codemycom
@Codemycom 4 жыл бұрын
pop it into base.html and see
@mehmetali1945
@mehmetali1945 4 жыл бұрын
@@Codemycom seems base has only access to home variables :)))) thx
@abhishekS195
@abhishekS195 4 жыл бұрын
hi, I have the same doubt. Does get_context_data(self,*args,**kwargs) gave base access to variables from class HomeView . also can we write get_context_data(self,*args,**kwargs) in any class view.
@athishga3096
@athishga3096 3 жыл бұрын
drop down menu is not working ... Could u help me to sort out this...?
@Codemycom
@Codemycom 3 жыл бұрын
what did you do differently from the video?
@plusk343
@plusk343 4 жыл бұрын
Heyy, a humble request, please do a setup reveal and recommend some setup tips to young and aspiring programmers. Please....
@Codemycom
@Codemycom 4 жыл бұрын
setup of what?
@plusk343
@plusk343 4 жыл бұрын
@@Codemycom Your computer and build and other things that are on your desk right now
@Codemycom
@Codemycom 4 жыл бұрын
@@plusk343 ah...it's not that exciting :-p my desk is in a film studio...
@plusk343
@plusk343 4 жыл бұрын
@@Codemycom PC specs???
@plusk343
@plusk343 4 жыл бұрын
Its always more exciting for the viewers than the creators! But as always, the last word's yours.
@tomyadam6851
@tomyadam6851 4 жыл бұрын
How to do category have parent category or sub category ? any idea
@Codemycom
@Codemycom 4 жыл бұрын
Would take too long to explain in a comment
@tomyadam6851
@tomyadam6851 4 жыл бұрын
@@Codemycom thank you for answering , can you make video to explain the sub category
@miranpolo7367
@miranpolo7367 3 жыл бұрын
help me my dropdown not open please
@rafiatunlubaba4254
@rafiatunlubaba4254 3 жыл бұрын
did you solve it?
@satyabansahoo1862
@satyabansahoo1862 3 жыл бұрын
@@rafiatunlubaba4254 Yes... Use this snippet Dropdown Action Another action Something else here
@mujassimjamal24
@mujassimjamal24 4 жыл бұрын
Sir, plz make videos on django tutorial for absolute beginners ❤
@Codemycom
@Codemycom 4 жыл бұрын
That's what this is
@robh9184
@robh9184 4 жыл бұрын
The trick is to start at the beginning of the playlist. Good Luck!
@Chibudomobasi
@Chibudomobasi 2 жыл бұрын
create a package
@Codemycom
@Codemycom 2 жыл бұрын
what does that mean? lol
@pauldzvonyk9044
@pauldzvonyk9044 10 ай бұрын
in your views.py, create: class CategoryMixin: def get_context_data(self, *args, **kwargs): cat_list = Category.objects.all() context = super().get_context_data(*args, **kwargs) context['cat_list'] = cat_list return context and inherit this class in other class Views, that will work just fine.
@hamzazahir1884
@hamzazahir1884 Жыл бұрын
category names with first letter as capital won't show anything and would give an error "Not Found, This page does not exist". how to fix this?
Style Our Blog With Bootstrap - Django Blog #3
19:51
Codemy.com
Рет қаралды 49 М.
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
Create Blog Like Button - Django Blog #18
19:35
Codemy.com
Рет қаралды 54 М.
I Redesigned the ENTIRE YouTube UI from Scratch
19:10
Juxtopposed
Рет қаралды 880 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 493 М.
How To Restrict Who Can Make Blog Posts - Django Blog #17
14:48
Codemy.com
Рет қаралды 18 М.
Learn Django in 20 Minutes!!
21:25
Tech With Tim
Рет қаралды 443 М.
How To Maximize Performance In Your React Apps
12:58
Web Dev Simplified
Рет қаралды 118 М.
Web Server Concepts and Examples
19:40
WebConcepts
Рет қаралды 266 М.
Add Profile Pic and Social Media Links - Django Blog #28
21:51
Codemy.com
Рет қаралды 24 М.
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН