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 Жыл бұрын
You my friend are a genius. How did you learn to do that?
@Codemycom4 жыл бұрын
▶️ 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
@shawnbeans73894 жыл бұрын
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.
@Codemycom4 жыл бұрын
Fun
@codedjango4 жыл бұрын
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 😁
@Codemycom4 жыл бұрын
Yeah I'll release the source code eventually...but you don't really need it...it's not all that extensive.
@spreadhysteria36504 жыл бұрын
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.
@Codemycom4 жыл бұрын
Glad you enjoy them :-)
@zubin16774 жыл бұрын
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.
@Codemycom4 жыл бұрын
Those things aren't related
@zoljargalenkhtaivan96613 жыл бұрын
I find every solutions of problems that confused me. Thank you man, I am from Mongolia.
@azimsonny60364 жыл бұрын
was waiting for your updates! :)
@Codemycom4 жыл бұрын
More to come! I post django blog videos monday, wednesday, and friday
@silaskanku73772 жыл бұрын
The category main page doesn't show the category nav item, how can I fix that?
@spreadhysteria36504 жыл бұрын
I want to put the navbar category in the category.html, but I can't figure it out.
@ali_sadrian2 жыл бұрын
Now still if we add a new category, we have to restart the server How do we fix that Sir?
@ZabeelBasheer4 жыл бұрын
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?
@Codemycom4 жыл бұрын
It's a little tricky...I sort of get into that later in the course
@hanadraskovic68394 жыл бұрын
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)
@marcelotedescodemiranda4013 жыл бұрын
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
@rafiatunlubaba42543 жыл бұрын
have you solved it
@silaskanku73772 жыл бұрын
How to display category nav in editprofilepage and showprofile page?
@RahulRoy-wo9dg4 жыл бұрын
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
@gamingmobility87342 жыл бұрын
absolutely underrated comment!
@raviv4694 жыл бұрын
How to use cat_menu dropdown menu in each category
@nikithashekhar1522 Жыл бұрын
cat_menu query set is not formed in my page i exactly followed you whats tht issue
@Codemycom Жыл бұрын
check your code, you think you followed exactly, but you missed something.
@jarvismillan25293 жыл бұрын
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.tanvirfoysal99423 жыл бұрын
I'm getting this error. Reverse for 'category' with keyword arguments '{'cats': ''}' not found. 1 pattern(s) tried: ['blog/category/(?P[^/]+)/$']
@anopta3 жыл бұрын
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_ccs4 жыл бұрын
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.
@Codemycom4 жыл бұрын
cool
@apolovzla_ccs4 жыл бұрын
@@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"?
@spreadhysteria36504 жыл бұрын
Did you manage to bring the drop-down menu category navbar, in the category.html?
@apolovzla_ccs4 жыл бұрын
@@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.
@angusgane19794 жыл бұрын
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)
@jayashanfernando47142 жыл бұрын
just add a category type in Caps lock on , but it doesnt shows any posts under that
@ffoofooify4 жыл бұрын
You are Amazing and funny from France :) continue
@Codemycom4 жыл бұрын
So nice of you to say!
@antonyjohn21634 жыл бұрын
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
@Codemycom4 жыл бұрын
Then it's not exactly as it is. You have a typo somewhere
@antonyjohn21634 жыл бұрын
@@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.
@Codemycom4 жыл бұрын
@@antonyjohn2163 I will sometime, but you'll have to rewatch the videos and retrace your steps in the mean time
@antonyjohn21634 жыл бұрын
@@Codemycom alright sir
@RahulPatil-m4 жыл бұрын
@@antonyjohn2163 did you get the solution??
@prahladthelord46684 жыл бұрын
Sir How to make the search function , In django blog to search for blog articles ? If Possible make a video plz
@Codemycom4 жыл бұрын
We may look at that
@solomonkassahun78454 жыл бұрын
damn you are the best thing of 2020 thank you!!!!
@Codemycom4 жыл бұрын
Thanks! Though being the best of 2020 is maybe a dubious honor ;-P LOL
@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 Жыл бұрын
what did you do differently from the video?
@jyotirani62384 жыл бұрын
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?
@fatimas64283 жыл бұрын
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
@jameskulu4 жыл бұрын
Is there any other solution for not repeating that code for listing category items in navbar?
@Codemycom4 жыл бұрын
of course, you can do it any way you like...there's always infinite ways to do a thing
@apolovzla_ccs4 жыл бұрын
@@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?
@iamnetwork94234 жыл бұрын
Sir, how to capitalize cat_menu_list
@nooobgamer014 жыл бұрын
great sir ❤❤
@Codemycom4 жыл бұрын
:-)
@mehmetali19454 жыл бұрын
does base.html has access to home.html variables we passed like cat_menu , if so is it specifically to home.html ?
@Codemycom4 жыл бұрын
pop it into base.html and see
@mehmetali19454 жыл бұрын
@@Codemycom seems base has only access to home variables :)))) thx
@abhishekS1954 жыл бұрын
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.
@athishga30963 жыл бұрын
drop down menu is not working ... Could u help me to sort out this...?
@Codemycom3 жыл бұрын
what did you do differently from the video?
@plusk3434 жыл бұрын
Heyy, a humble request, please do a setup reveal and recommend some setup tips to young and aspiring programmers. Please....
@Codemycom4 жыл бұрын
setup of what?
@plusk3434 жыл бұрын
@@Codemycom Your computer and build and other things that are on your desk right now
@Codemycom4 жыл бұрын
@@plusk343 ah...it's not that exciting :-p my desk is in a film studio...
@plusk3434 жыл бұрын
@@Codemycom PC specs???
@plusk3434 жыл бұрын
Its always more exciting for the viewers than the creators! But as always, the last word's yours.
@tomyadam68514 жыл бұрын
How to do category have parent category or sub category ? any idea
@Codemycom4 жыл бұрын
Would take too long to explain in a comment
@tomyadam68514 жыл бұрын
@@Codemycom thank you for answering , can you make video to explain the sub category
@miranpolo73673 жыл бұрын
help me my dropdown not open please
@rafiatunlubaba42543 жыл бұрын
did you solve it?
@satyabansahoo18623 жыл бұрын
@@rafiatunlubaba4254 Yes... Use this snippet Dropdown Action Another action Something else here
@mujassimjamal244 жыл бұрын
Sir, plz make videos on django tutorial for absolute beginners ❤
@Codemycom4 жыл бұрын
That's what this is
@robh91844 жыл бұрын
The trick is to start at the beginning of the playlist. Good Luck!
@Chibudomobasi2 жыл бұрын
create a package
@Codemycom2 жыл бұрын
what does that mean? lol
@pauldzvonyk904410 ай бұрын
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 Жыл бұрын
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?