▶️ Watch Entire Django Blog Playlist ✅ Subscribe To My TH-cam 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
thanks for this! im stuck with my project for 2 days now and ive been thinking so complex when the solution is just so simple! u got new subscriber here!
Hey John! Just wanted to thank you for a kickass TH-cam series on how to create a blog with Django! My website is coming along nicely thanks to you! By the way: Any chance you will be able to cover some of these topics? 1. How to edit the link for the blog post Back button, so that it goes back to the page you came from (e.g. Home, Category Page, and possibly to the previous article (if you came from one that had links to other articles) 2. Custom CSS styling of elements 3. Category creation: How to create an if statement to see if the category has already been created (if so: display error message) Thanks again! :)
Hello, thank you very much for awesome videos! It really helps! One Question on the Add Categories, as we need to restart the server everytime we add a category to reflect in the Add Blog Form, is there any way to avoid restarting server and make it available to Add Blog?
You always say insanely cheap by looking the top... Why this time looking down...😂 And, your and this series is insanely useful for me...😀
4 ปีที่แล้ว +3
Hello, thank you very much for these videos! One question please when I want to use Class-based view for CategoryView, is that definition in 'views.py' correct? class CategoryView(ListView): model = Category template_name = 'categories.html' def get_queryset(self): return Category.objects.filter(category=self.kwargs.get('name'))
Hi John. Perfectly explained about categorization, but ... when deleting a post and if it was the last post with this category, the category name remains in the general list of categories. how to solve this issue so that the program monitors and deletes the category name if there are no more posts on this category? thanx in advance, Vik.
I would say the best way to get the categories thing working as intended is to create the category field in Post model by using models.ManyToManyField. (Creating a relation in db where one post can have many categories and one category can be used in many posts) Create a separate model for Categories which is going to store all of your categories no matter if they are currently used or not. It also solves the problem with adding multiple categories to one post. And honestly as an admin of a blog you don't really want to allow all of the registered users to create their own categories xD Though i understand that what John shows is just a simplistic way of introducing it
I think u forgot write edit for Category i mean change it when want to edit post can change category too , and i want when a new post is added in the blog, no one can click the admin option from the author's section, what should I do?
i found the answer, you need to add order_by ('- post_date') to views / category_post to get it like this: def CategoryView(request, cats): category_posts = Post.objects.filter(category = cats). order_by('-post_date') return render(request, 'categories.html', {'cats':cats.title(), 'category_posts':category_posts}) I hope someone will help
just wondering where i went wrong, i have 5 categories on my categories dropdown,now when i click on the 3 of them they are displaying pages well, the rest appear squeezed and very small when clicked. I tried to add more categories and they all appear squeezed, only the first 3 look nice, any suggestions where i could have gone wrong.... thanks
Hello, i hope everyones doing great! I was wondering if there was a solution to update the newly added category without relaunching the server? Thanks in advance!
I'm getting this error, can someone please help NoReverseMatch at / Reverse for 'category' with arguments '('',)' not found. 1 pattern(s) tried: ['category/(?P[^/]+)/$']
I have been stuck on this category thingy for the past two days, i could never get it working fully either some are showing and others aren't or all the categories aren't showing. And I would like to point out that the query works fine and display of the {cats} in the browser too, however once i try to load my categories.html it goes straight to "Sorry no such page exist yet !!". Is driving me insane , any assistance will be much appreciated
This is insanely helpful - thank you so much! I'm wondering what to do if your post categories is a ManyToMany field and you can't necessarily filter with the filter equals (ie Post.objects.filter(category=cats)? Is there a workaround in that scenario? Thanks so much!
@@Codemycom Of course! I actually solved it by filtering on whether the title of the ManyToMany category field contained the cats string (ie Post.objects.filter(category__name__contains=cats) which worked! Thanks for the fast reply and helpful videos
I search for category page in django...but didn’t find...this is the specific video that I am searching. You can add some Tags in video. Sothat we can find it easily when we are searching.
Multiple categories is good if you are looking for a specific thing If it were coding, then you might look for django and also maybe authentication or you maybe look for python etc.
As soon as I add the category_posts line in my views, my URL stops working and is throwing an invalid literal for int() with base 10. I remove that line and I see the name on the page fine, put it back and boom, the int() error again. I am using Python 3. Did I miss something?
I noticed that on the home page, when I click on a category next to one of the posts to show only posts from that category that the posts on the resulting category page are not shown in reverse order by either id or date_posted. I'm wondering if this is because we used a functional rather than class based approach. I don't know if anyone else has seen this. Is there an easy way to order the posts on that page? Thanks!
I had the same issue, it was due to filter not matching capital letters from my categories, you have to make sure your categories are added in lowecase so it match with the cats in the url. Once you have changed it, you have to reassign the category or it will keep showing the older one
Hey John, Thank you so much for the well-made video, very explanatory. Just one question, it seems that whenever I create a category with a capital letter in the beginning, the query set doesn't recognize the category's posts, and therefore doesn't display anything in categories.html. Only when I register a low case letters it works proper. I tried looking in any way to solve it, I would need your help with that. Thanks in advance!
Hello! I had the exact problem and I did some searching and found out the solution. All you gotta do is add '__iexact' in your filter method like so : category_posts = Post.objects.filter(category__iexact=cats) Hope this helps!
@@atharvamahadik9156 This just helped me man lol. I had a different problem but i thought to apply your solution and see if it works. It did! Thanks man!
I love this playlist! I'd love to be able to add a button to a website and filter my models by clicking the button. (and present a slugified URL in the browser). Does the code you use work if I add it to a button instead of blog link like in your example?
Yeah I have same problem """ def CategoryView(request, cats): category_posts = VideoPost.objects.filter(category=cats) return render(request, 'categories.html', {'cats':cats, 'category_posts':category_posts}) """ is there something wrong in there?
I found my own problem, maybe help you CATEGORY_CHOICES = ( ('GUNCEL','Güncel'), ('AKAID','Akaid'), ('TEFSIR','Tefsir'), ('FIKIH','Fıkıh'), ('HADIS','Hadis') ) localhost:8000/category/AKAID/ if I search as "akaid" query return empty but when I try to search with key it's okay. Maybe you have 'Coding' and you search 'coding' instead of 'Coding'
Is it possible to upload this to github? I've followed the lesson really closely but I can only get the category name to appear in the page - I can't get the posts belonging to that category from the for loop. Thanks!
hi love what your doing here!! but i do have a Question.. when you go to the url localhost:8000/category/ u get "Page not found (404) Request Method: GET Request URL: localhost:8000/category/" is there a quick fix for this?
Hi Codemy, I am trying to make a profile page where the user can select blog categories then submit those. Then the homepage will only show blogs that are under those selected categories. How can I do this instead of creating a separate category page for each category?
I believe you would want a DetailView with method named queryset with something like Blog.objecs.filter(category__exact='someCategory') but that's if you're using a many to many or foreign key
Actually it would be more 'suitable' to use a ListView class SomeView(ListView): model = Blog ... def get_queryset(self): return Blog.objects.filter(category__exact='sports')
▶️ Watch Entire Django Blog Playlist ✅ Subscribe To My TH-cam 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
Wow, Just watched this video now and everything is just easy and awesome, Codemy still remains the best, I love it.
Happy to hear it!
thanks for this! im stuck with my project for 2 days now and ive been thinking so complex when the solution is just so simple!
u got new subscriber here!
Awesome! Glad it worked out for you!
Hey John! Just wanted to thank you for a kickass TH-cam series on how to create a blog with Django! My website is coming along nicely thanks to you!
By the way: Any chance you will be able to cover some of these topics?
1. How to edit the link for the blog post Back button, so that it goes back to the page you came from (e.g. Home, Category Page, and possibly to the previous article (if you came from one that had links to other articles)
2.
Custom CSS styling of elements
3. Category creation: How to create an if statement to see if the category has already been created (if so: display error message)
Thanks again! :)
I think you can set fields to be unique in the models. So if someone tries to add a category that exists there should be an error message.
It would be really great if you could give a link to your website. Would love to see a real product.
absolutely best django tutorial
Glad you think so!
Sir category_post not fetching anything in html page
Please need help
Hello, thank you very much for awesome videos! It really helps! One Question on the Add Categories, as we need to restart the server everytime we add a category to reflect in the Add Blog Form, is there any way to avoid restarting server and make it available to Add Blog?
thanks for the video. waiting for comments pagination kind of thing next. thanks again. :)
Coming soon!
Thanks for everything,
When I use special chracters such as ü ş code is not working on the line and content.
How solve it?
Awesome explanation thank you waiting for next video
So nice of you
Best of best channel
Thanks!!
hello sir, i wanted to post author automatically by which id user is logged in because here a logged in user can select any author
Keep watching the videos, we resolve that later.
You always say insanely cheap by looking the top... Why this time looking down...😂
And, your and this series is insanely useful for me...😀
Hello, thank you very much for these videos! One question please when I want to use Class-based view for CategoryView, is that definition in 'views.py' correct?
class CategoryView(ListView):
model = Category
template_name = 'categories.html'
def get_queryset(self):
return Category.objects.filter(category=self.kwargs.get('name'))
how would one modify the paths htmls etc... accordingly?
Hi John. Perfectly explained about categorization, but ... when deleting a post and if it was the last post with this category, the category name remains in the general list of categories. how to solve this issue so that the program monitors and deletes the category name if there are no more posts on this category? thanx in advance, Vik.
I would say the best way to get the categories thing working as intended is to create the category field in Post model by using models.ManyToManyField. (Creating a relation in db where one post can have many categories and one category can be used in many posts)
Create a separate model for Categories which is going to store all of your categories no matter if they are currently used or not. It also solves the problem with adding multiple categories to one post.
And honestly as an admin of a blog you don't really want to allow all of the registered users to create their own categories xD Though i understand that what John shows is just a simplistic way of introducing it
I think u forgot write edit for Category i mean change it when want to edit post can change category too , and i want when a new post is added in the blog, no one can click the admin option from the author's section, what should I do?
thanks a lot of any second u spend for teatching us
You're Very Welcome!
After adding a new category we have to migrate our project. It doesn't automatically shows in the selection list while adding new post
I have a question, but how can I make the articles in the selected category sorted by -id?
i found the answer, you need to add order_by ('- post_date') to views / category_post to get it like this:
def CategoryView(request, cats):
category_posts = Post.objects.filter(category = cats). order_by('-post_date')
return render(request, 'categories.html', {'cats':cats.title(), 'category_posts':category_posts})
I hope someone will help
I really like your videos. I've learnt a lot from it.
Happy to hear that!
just wondering where i went wrong, i have 5 categories on my categories dropdown,now when i click on the 3 of them they are displaying pages well, the rest appear squeezed and very small when clicked. I tried to add more categories and they all appear squeezed, only the first 3 look nice, any suggestions where i could have gone wrong.... thanks
Thank you for making this video.
Hello, i hope everyones doing great! I was wondering if there was a solution to update the newly added category without relaunching the server? Thanks in advance!
use forign key insted of that query
How to fix needs runserver after add new category to category
I'm getting this error, can someone please help
NoReverseMatch at /
Reverse for 'category' with arguments '('',)' not found. 1 pattern(s) tried: ['category/(?P[^/]+)/$']
I have been stuck on this category thingy for the past two days, i could never get it working fully either some are showing and others aren't or all the categories aren't showing. And I would like to point out that the query works fine and display of the {cats} in the browser too, however once i try to load my categories.html it goes straight to "Sorry no such page exist yet !!". Is driving me insane , any assistance will be much appreciated
If i can see your code then I should be able to help you. I believe you have fixed it already though.
Sir how to populate the categories list into navbar ?
Good suggestion!
This is insanely helpful - thank you so much! I'm wondering what to do if your post categories is a ManyToMany field and you can't necessarily filter with the filter equals (ie Post.objects.filter(category=cats)? Is there a workaround in that scenario? Thanks so much!
Probably, but I'd have to think it over first :-p
@@Codemycom Of course! I actually solved it by filtering on whether the title of the ManyToMany category field contained the cats string (ie Post.objects.filter(category__name__contains=cats) which worked! Thanks for the fast reply and helpful videos
Hello, i have no idea how to add categories and not have to restart the server. can anyone please help me out? thanks
I search for category page in django...but didn’t find...this is the specific video that I am searching. You can add some Tags in video. Sothat we can find it easily when we are searching.
I have tags on all my videos and you can search for them on my channel page
Multiple categories is good if you are looking for a specific thing
If it were coding, then you might look for django and also maybe authentication
or you maybe look for python etc.
As soon as I add the category_posts line in my views, my URL stops working and is throwing an invalid literal for int() with base 10. I remove that line and I see the name on the page fine, put it back and boom, the int() error again. I am using Python 3. Did I miss something?
yes lol though I can't guess what.
I'm having exactly the same error
@@trailbleza Well don't expect him to help you. LOL
@@tynercreek79 I later found a method Denis Ivy used useful. The add categories done with just three lines of code.
I am having the same trouble!! Did anyone solve it?
I watched the video twice. So I smashed the like button twice and realized that I just unliked it. So, I watched thrice to like it😁
*Support = ∞*
Ha thanks!
Excellent
Thanks
valuable content
Thanks!
I noticed that on the home page, when I click on a category next to one of the posts to show only posts from that category that the posts on the resulting category page are not shown in reverse order by either id or date_posted. I'm wondering if this is because we used a functional rather than class based approach. I don't know if anyone else has seen this. Is there an easy way to order the posts on that page? Thanks!
This might help:
th-cam.com/video/EMsxxkkVDiI/w-d-xo.html
Category page not showing anything accept name of category
I had the same issue, it was due to filter not matching capital letters from my categories, you have to make sure your categories are added in lowecase so it match with the cats in the url. Once you have changed it, you have to reassign the category or it will keep showing the older one
@@JaviMstv You are a genius man. I tried every solution but this one fixed the problem. thank you man
Hey John,
Thank you so much for the well-made video, very explanatory.
Just one question, it seems that whenever I create a category with a capital letter in the beginning,
the query set doesn't recognize the category's posts, and therefore doesn't display anything in categories.html.
Only when I register a low case letters it works proper.
I tried looking in any way to solve it, I would need your help with that.
Thanks in advance!
Hello!
I had the exact problem and I did some searching and found out the solution.
All you gotta do is add '__iexact' in your filter method like so :
category_posts = Post.objects.filter(category__iexact=cats)
Hope this helps!
@@atharvamahadik9156 This just helped me man lol. I had a different problem but i thought to apply your solution and see if it works. It did! Thanks man!
@@hengage537 glad I was of help! goodluck👍
@@atharvamahadik9156 thanks so much
@@atharvamahadik9156 Thanks man! Appreciate it
I love this playlist! I'd love to be able to add a button to a website and filter my models by clicking the button. (and present a slugified URL in the browser). Does the code you use work if I add it to a button instead of blog link like in your example?
links and buttons are identical...a button is just a link with a bootstrap button class on it.
@@Codemycom Good point!
Ty 🤗🤗
Sure thing
I can't tell why my category_posts returns an empty querry. When I print {{ category_posts }} I end up with QuerrySet = []
Must be an error in your code somewhere...retrace the steps in the video.
Same problem with me too sir
Please help
@@manjunathkalal6329 solve hua ?
Yeah I have same problem
"""
def CategoryView(request, cats):
category_posts = VideoPost.objects.filter(category=cats)
return render(request, 'categories.html', {'cats':cats, 'category_posts':category_posts})
"""
is there something wrong in there?
I found my own problem, maybe help you
CATEGORY_CHOICES = (
('GUNCEL','Güncel'),
('AKAID','Akaid'),
('TEFSIR','Tefsir'),
('FIKIH','Fıkıh'),
('HADIS','Hadis')
)
localhost:8000/category/AKAID/
if I search as "akaid" query return empty
but when I try to search with key it's okay. Maybe you have 'Coding' and you search 'coding' instead of 'Coding'
Is it possible to upload this to github? I've followed the lesson really closely but I can only get the category name to appear in the page - I can't get the posts belonging to that category from the for loop. Thanks!
I will eventually, but that won't help you. There's an error in your code...you'll have to rewatch the videos to find it
@@Codemycom Ok, found the error now!
@@petecodes Great!
@@petecodes hi, what was your solution to resolve it please?
@@claudeihany4056 Sorry, don't remember but the video will show you correct way :)
Sir, is it possible to update the newly added category without relaunching the server?
Have you found any solution for that?
will you add more videos to this series??
Possibly
awesome!
:-)
hi love what your doing here!! but i do have a Question.. when you go to the url localhost:8000/category/ u get "Page not found (404)
Request Method: GET
Request URL: localhost:8000/category/" is there a quick fix for this?
have you solved this?
There's a problem with adding a new category now,
It gives an error
Solved now.
Thanks
cool
Sir It solve my problem thanks sir
Most welcome
👍👍
:-)
"""
def CategoryView(request, cats):
category_posts = VideoPost.objects.filter(category=cats)
# I think this filter is wrong so category item cant calling ("filter(category=cats)")
return render(request, 'categories.html', {'cats':cats, 'category_posts':category_posts})
"""
Hi Codemy, I am trying to make a profile page where the user can select blog categories then submit those. Then the homepage will only show blogs that are under those selected categories. How can I do this instead of creating a separate category page for each category?
I believe you would want a DetailView with method named queryset with something like Blog.objecs.filter(category__exact='someCategory') but that's if you're using a many to many or foreign key
Actually it would be more 'suitable' to use a ListView
class SomeView(ListView):
model = Blog
...
def get_queryset(self):
return Blog.objects.filter(category__exact='sports')
If you get weird not defined errors try putting quotation marks around the "category__exact"