Blog Category Pages - Django Blog #13

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ม.ค. 2025

ความคิดเห็น •

  • @Codemycom
    @Codemycom  4 ปีที่แล้ว +3

    ▶️ 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

  • @jamescarly2408
    @jamescarly2408 2 ปีที่แล้ว

    Wow, Just watched this video now and everything is just easy and awesome, Codemy still remains the best, I love it.

    • @Codemycom
      @Codemycom  2 ปีที่แล้ว

      Happy to hear it!

  • @angelu9429
    @angelu9429 4 ปีที่แล้ว

    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!

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      Awesome! Glad it worked out for you!

  • @kennethjohanangeltun9574
    @kennethjohanangeltun9574 4 ปีที่แล้ว +3

    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! :)

    • @petecodes
      @petecodes 4 ปีที่แล้ว

      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.

    • @smishra6378
      @smishra6378 3 ปีที่แล้ว

      It would be really great if you could give a link to your website. Would love to see a real product.

  • @mehmetali1945
    @mehmetali1945 4 ปีที่แล้ว +2

    absolutely best django tutorial

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      Glad you think so!

  • @manjunathkalal6329
    @manjunathkalal6329 4 ปีที่แล้ว +2

    Sir category_post not fetching anything in html page
    Please need help

  • @abdulslogin9055
    @abdulslogin9055 4 ปีที่แล้ว +4

    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?

  • @azimsonny6036
    @azimsonny6036 4 ปีที่แล้ว +1

    thanks for the video. waiting for comments pagination kind of thing next. thanks again. :)

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      Coming soon!

  • @cemsecim
    @cemsecim 3 ปีที่แล้ว

    Thanks for everything,
    When I use special chracters such as ü ş code is not working on the line and content.
    How solve it?

  • @chethanmgowda8718
    @chethanmgowda8718 4 ปีที่แล้ว

    Awesome explanation thank you waiting for next video

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      So nice of you

  • @bipulvishwakarma4675
    @bipulvishwakarma4675 3 ปีที่แล้ว

    Best of best channel

  • @nooobgamer01
    @nooobgamer01 4 ปีที่แล้ว +2

    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

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +4

      Keep watching the videos, we resolve that later.

  • @vinothv1720
    @vinothv1720 4 ปีที่แล้ว

    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'))

    • @User-lc4zo
      @User-lc4zo 3 ปีที่แล้ว

      how would one modify the paths htmls etc... accordingly?

  • @viksir4278
    @viksir4278 2 ปีที่แล้ว

    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.

    • @DevMP
      @DevMP 2 ปีที่แล้ว

      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

  • @hosseingharsi4497
    @hosseingharsi4497 ปีที่แล้ว

    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?

  • @nabilm791
    @nabilm791 4 ปีที่แล้ว

    thanks a lot of any second u spend for teatching us

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      You're Very Welcome!

  • @ketchupparty9997
    @ketchupparty9997 3 ปีที่แล้ว

    After adding a new category we have to migrate our project. It doesn't automatically shows in the selection list while adding new post

  • @darwinsterritory
    @darwinsterritory 3 ปีที่แล้ว +1

    I have a question, but how can I make the articles in the selected category sorted by -id?

    • @darwinsterritory
      @darwinsterritory 3 ปีที่แล้ว

      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

  • @AmoahDevLabs
    @AmoahDevLabs 4 ปีที่แล้ว

    I really like your videos. I've learnt a lot from it.

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +2

      Happy to hear that!

  • @elegantdigitalskills3073
    @elegantdigitalskills3073 4 ปีที่แล้ว

    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

  • @dipeshmandanka5607
    @dipeshmandanka5607 3 ปีที่แล้ว

    Thank you for making this video.

  • @diegoaranab7313
    @diegoaranab7313 3 ปีที่แล้ว +1

    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!

    • @mryaz9767
      @mryaz9767 3 ปีที่แล้ว

      use forign key insted of that query

  • @dinindutheekshana2254
    @dinindutheekshana2254 3 ปีที่แล้ว

    How to fix needs runserver after add new category to category

  • @akashgautam8061
    @akashgautam8061 2 หลายเดือนก่อน

    I'm getting this error, can someone please help
    NoReverseMatch at /
    Reverse for 'category' with arguments '('',)' not found. 1 pattern(s) tried: ['category/(?P[^/]+)/$']

  • @ifmacinema
    @ifmacinema 3 ปีที่แล้ว

    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

    • @hengage537
      @hengage537 3 ปีที่แล้ว

      If i can see your code then I should be able to help you. I believe you have fixed it already though.

  • @prahladthelord4668
    @prahladthelord4668 4 ปีที่แล้ว +2

    Sir how to populate the categories list into navbar ?

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +2

      Good suggestion!

  • @michaelmccarthy2078
    @michaelmccarthy2078 4 ปีที่แล้ว +1

    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
      @Codemycom  4 ปีที่แล้ว

      Probably, but I'd have to think it over first :-p

    • @michaelmccarthy2078
      @michaelmccarthy2078 4 ปีที่แล้ว +4

      @@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

  • @domdes14
    @domdes14 2 ปีที่แล้ว

    Hello, i have no idea how to add categories and not have to restart the server. can anyone please help me out? thanks

  • @mainulislamfaruqi
    @mainulislamfaruqi 4 ปีที่แล้ว

    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.

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      I have tags on all my videos and you can search for them on my channel page

  • @AttentionModeHumbleEst2022
    @AttentionModeHumbleEst2022 3 ปีที่แล้ว

    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.

  • @charlottewood9538
    @charlottewood9538 4 ปีที่แล้ว +1

    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?

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      yes lol though I can't guess what.

    • @trailbleza
      @trailbleza 4 ปีที่แล้ว

      I'm having exactly the same error

    • @tynercreek79
      @tynercreek79 4 ปีที่แล้ว

      @@trailbleza Well don't expect him to help you. LOL

    • @trailbleza
      @trailbleza 4 ปีที่แล้ว

      @@tynercreek79 I later found a method Denis Ivy used useful. The add categories done with just three lines of code.

    • @miryamelliye
      @miryamelliye 4 ปีที่แล้ว +1

      I am having the same trouble!! Did anyone solve it?

  • @plusk343
    @plusk343 4 ปีที่แล้ว +1

    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 = ∞*

  • @milliondollarmotivation6260
    @milliondollarmotivation6260 4 ปีที่แล้ว

    Excellent

  • @dipeshmandanka5607
    @dipeshmandanka5607 3 ปีที่แล้ว

    valuable content

  • @briangreenberg153
    @briangreenberg153 3 ปีที่แล้ว

    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!

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว

      This might help:
      th-cam.com/video/EMsxxkkVDiI/w-d-xo.html

  • @nasimansari6041
    @nasimansari6041 4 ปีที่แล้ว +2

    Category page not showing anything accept name of category

    • @JaviMstv
      @JaviMstv 3 ปีที่แล้ว

      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

    • @tony-sn9sl
      @tony-sn9sl 2 ปีที่แล้ว +1

      @@JaviMstv You are a genius man. I tried every solution but this one fixed the problem. thank you man

  • @idancohen4995
    @idancohen4995 3 ปีที่แล้ว

    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!

    • @atharvamahadik9156
      @atharvamahadik9156 3 ปีที่แล้ว +3

      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!

    • @hengage537
      @hengage537 3 ปีที่แล้ว +1

      @@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!

    • @atharvamahadik9156
      @atharvamahadik9156 3 ปีที่แล้ว +1

      @@hengage537 glad I was of help! goodluck👍

    • @mijeme2564
      @mijeme2564 3 ปีที่แล้ว +1

      @@atharvamahadik9156 thanks so much

    • @aymanisam
      @aymanisam 3 ปีที่แล้ว +1

      @@atharvamahadik9156 Thanks man! Appreciate it

  • @petecodes
    @petecodes 4 ปีที่แล้ว

    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?

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      links and buttons are identical...a button is just a link with a bootstrap button class on it.

    • @petecodes
      @petecodes 4 ปีที่แล้ว

      @@Codemycom Good point!

  • @hitmeup7003
    @hitmeup7003 3 ปีที่แล้ว

    Ty 🤗🤗

  • @pokotyec
    @pokotyec 4 ปีที่แล้ว +1

    I can't tell why my category_posts returns an empty querry. When I print {{ category_posts }} I end up with QuerrySet = []

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +1

      Must be an error in your code somewhere...retrace the steps in the video.

    • @manjunathkalal6329
      @manjunathkalal6329 4 ปีที่แล้ว

      Same problem with me too sir
      Please help

    • @im_sanjay
      @im_sanjay 4 ปีที่แล้ว

      @@manjunathkalal6329 solve hua ?

    • @enes222
      @enes222 3 ปีที่แล้ว

      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?

    • @enes222
      @enes222 3 ปีที่แล้ว

      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'

  • @petecodes
    @petecodes 4 ปีที่แล้ว

    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!

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      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

    • @petecodes
      @petecodes 4 ปีที่แล้ว

      @@Codemycom Ok, found the error now!

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      @@petecodes Great!

    • @claudeihany4056
      @claudeihany4056 3 ปีที่แล้ว

      @@petecodes hi, what was your solution to resolve it please?

    • @petecodes
      @petecodes 3 ปีที่แล้ว

      @@claudeihany4056 Sorry, don't remember but the video will show you correct way :)

  • @007rahulb
    @007rahulb 4 ปีที่แล้ว

    Sir, is it possible to update the newly added category without relaunching the server?

    • @XeUs87
      @XeUs87 4 ปีที่แล้ว

      Have you found any solution for that?

  • @sakibshabir1785
    @sakibshabir1785 4 ปีที่แล้ว

    will you add more videos to this series??

  • @nooobgamer01
    @nooobgamer01 4 ปีที่แล้ว

    awesome!

  • @tdnight8660
    @tdnight8660 4 ปีที่แล้ว

    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?

  • @dradrigapatrick
    @dradrigapatrick 4 ปีที่แล้ว

    There's a problem with adding a new category now,
    It gives an error

  • @ayushtripathi2605
    @ayushtripathi2605 4 ปีที่แล้ว

    Sir It solve my problem thanks sir

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      Most welcome

  • @nooobgamer01
    @nooobgamer01 4 ปีที่แล้ว

    👍👍

  • @enes222
    @enes222 3 ปีที่แล้ว +2

    """
    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})
    """

  • @ad.8100
    @ad.8100 4 ปีที่แล้ว

    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?

    • @sayori3939
      @sayori3939 2 ปีที่แล้ว

      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

    • @sayori3939
      @sayori3939 2 ปีที่แล้ว

      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')

    • @sayori3939
      @sayori3939 2 ปีที่แล้ว

      If you get weird not defined errors try putting quotation marks around the "category__exact"