How To Slugify Category Page URLs - Django Blog #14

  Рет қаралды 35,003

Codemy.com

Codemy.com

Күн бұрын

Пікірлер: 106
@robh9184
@robh9184 4 жыл бұрын
Im feeling rather sluggified after smashing through 14 Django tutorials.. 5 more to goo!! Learning lots here thanks mate!
@Codemycom
@Codemycom 4 жыл бұрын
ha fun
@pentestPY
@pentestPY 7 күн бұрын
Just watched this slugify video.. awesome, learned we can slugify and just delete the space and replace it with hyphen.. This thing is cool
@pooriyayousefi7914
@pooriyayousefi7914 3 жыл бұрын
you are a legend ! you are covering every concept that a blog needs . I don't google anymore :)) I use your videos xD big ups
@Codemycom
@Codemycom 3 жыл бұрын
I appreciate that!
@saeedyaqoob5784
@saeedyaqoob5784 3 жыл бұрын
Here is a solution to the case problem: Just add this to your Category model in models.py to override its existing save method. def save(self, *args, **kwargs): self.name = self.name.lower() return super(Category, self).save(*args, **kwargs) It will make sure every new entry/category is saved as lowercase in your database. You might have to remove the existing categories saved as title or uppercase. Hope this helps. @John Really helpful videos. Learning a lot from them. Keep up the good work.
@marz4964
@marz4964 2 жыл бұрын
Coding is working but newly added Car or Entertainment not working..your code works..but category lists show all lower case i dont like it what can i do?
@thattrollagen
@thattrollagen 4 жыл бұрын
For anyone having issues: Instead of: def CategoryView(request, cats): category_posts = Post.objects.filter(category=cats.replace('-', ' ')) return render(request, 'categories.html', {'cats':cats.title().replace('-', ' '), 'category_posts':category_posts}) Do: def CategoryView(request, cats): category_posts = Post.objects.filter(category=cats.title().replace('-', ' ')) return render(request, 'categories.html', {'cats':cats.title().replace('-', ' '), 'category_posts':category_posts})
@michaeldiehl-citoli3792
@michaeldiehl-citoli3792 4 жыл бұрын
Thanks! This fixed my "This page is not valid." error.
@maramsagheer3399
@maramsagheer3399 2 жыл бұрын
nice tutorial. i ran into a small issue where the normal categories wouldnt work after adding the slugify so i fixed it like this in case anyone was wondering. {% if " " in category.name %} {{ post.category }} {% else %} {{ post.category }} {% endif %}
@Ali_Alhajji
@Ali_Alhajji 2 жыл бұрын
Great tutorial! The way I would solve the space in the URL is adding a new field in the Category model for the URL. For example, "coding tutorial" category would have another field "coding-tutorial" and I would use that in the URL.
@hariharanbalasubramanianpr4243
@hariharanbalasubramanianpr4243 4 жыл бұрын
SIr, When I try to slugify in the url its showing %20 instead of '-'. In my views.py under the categoryView I gave this def CategoryView(request, cats): category_post = Post.objects.filter(category = cats.replace('-', ' ')) return render(request, 'categories.html', {'cats':cats.title().replace('-', ' '), 'category_post':category_post}) What can be the mistake sir.. Thanks,
@animalcompilations832
@animalcompilations832 4 жыл бұрын
the same with me, and if you try the url with '-' the title delete the space between words
@smishra6378
@smishra6378 3 жыл бұрын
Can you show the code in your home.html? You need to modify the url link of post.category in home.html, like this- - {{ post.category }}
@shawnbeans7389
@shawnbeans7389 4 жыл бұрын
good job codemy very nice. 👍👍👍
@Codemycom
@Codemycom 4 жыл бұрын
Thank you! 👍
@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
@danielscheurwater5500
@danielscheurwater5500 4 жыл бұрын
Thanks for all these vids man! Really helpfull!
@Codemycom
@Codemycom 4 жыл бұрын
Glad you like them!
@milliondollarmotivation6260
@milliondollarmotivation6260 4 жыл бұрын
*Congratulations 40 K Subs*
@Codemycom
@Codemycom 4 жыл бұрын
Thanks!
@vinothv1720
@vinothv1720 4 жыл бұрын
But in my browser, instead of white space, Am getting "coding%20tutorials"... Even before adding slugify in that href... After adding also, I get the same... Not getting - instead of space... Why?
@eduardobranco3490
@eduardobranco3490 4 жыл бұрын
Cheers from Portugal! One thing , when we add a new category and write the name capitalised, we are sent to the "Sorry this page does not exist..." We must have to write with no caps, maybe because of the '.title()' object. You are great, thanks a lot!
@Codemycom
@Codemycom 4 жыл бұрын
Could be...play around with it and see.
@joseparedes4260
@joseparedes4260 4 жыл бұрын
Filter using __iexact which takes all the arguments ignoring upper and lower case For example: Post.objects.filter(category__iexact=cats)
@angelraya8602
@angelraya8602 4 жыл бұрын
@@joseparedes4260 Thanks alot man! This had me stumped lol
@ranvijaysingh7967
@ranvijaysingh7967 3 жыл бұрын
@@joseparedes4260 thanks buddy it helped
@user-dy5ho4sj2w
@user-dy5ho4sj2w 3 жыл бұрын
@@joseparedes4260 Worked for me too. Thank you! :)
@prusa16
@prusa16 3 жыл бұрын
I found the solution: When i add new category first letters are big but when i add new category first letters are small, it works. Hey John, thanks for your videos, great resources... And i have a problem with slugify... I am using latest django and i did same codes with yours... def CategoryView(request, cats): category_posts = Post.objects.filter(category=cats.replace('-', ' ')) return render(request, 'categories.html', {'cats': cats.title().replace('-', ' '), 'category_posts':category_posts}) But i still have a sorry page doesnt exist. I also check typo errors but nothing :( Could you solve this?
@abhishekgawali165
@abhishekgawali165 4 жыл бұрын
Great job man, loved it
@Codemycom
@Codemycom 4 жыл бұрын
Thanks a lot!
@abhayamagdum4652
@abhayamagdum4652 4 жыл бұрын
Hey.. I'm just loving the way you teach😊 I am getting %20 in URL for space and unable to slugify it. URL with space is invalid in my case. Please suggest
@Codemycom
@Codemycom 4 жыл бұрын
Check your code for errors
@samuellee1431
@samuellee1431 4 жыл бұрын
What worked for me was in my views python file, I had to add .title() in my Post.objects.filter in the CategoryView function. Original: CategoryView(request, cats): category_posts = Post.objects.filter(category = cats.replace('-', ' ')) ....,etc. After: CategoryView(request,cats): category_posts = Post.objects.filter(category = cats.title().replace('-', ' ')
@kykurniawan
@kykurniawan 4 жыл бұрын
@@samuellee1431 thanks this saved my time
@narayanpanta1668
@narayanpanta1668 3 жыл бұрын
@@samuellee1431 Thank you so much you save my time
@athishga3096
@athishga3096 3 жыл бұрын
@@samuellee1431 thanks a lot dood.. It helped me alot....
@htshongany4969
@htshongany4969 4 жыл бұрын
Hi I like your videos I have difficulty with english but I understand that very well
@htshongany4969
@htshongany4969 4 жыл бұрын
I realized that when the category is upper-case, it can be a problem
@Codemycom
@Codemycom 4 жыл бұрын
Glad you like them
@Codemycom
@Codemycom 4 жыл бұрын
@@htshongany4969 You could write some code to change everything to lowercase if you have a problem with it
@htshongany4969
@htshongany4969 4 жыл бұрын
I'm looking for a solution
@htshongany4969
@htshongany4969 4 жыл бұрын
I tried yesterday and I've had some unexpected behavior. I plan to try again today.
@ogananfe
@ogananfe 2 жыл бұрын
Excellent tutorial💞👍 but i think we have a bug. What happens if someone happens to name a category "co-operative"? There would be no match in the module once we decide to replace all the "-" with spaces because we would be looking for co operative in the database. I feel like we should have used primary keys instead of category names in the urls.
@sgtdypen
@sgtdypen Жыл бұрын
categories will be listed in the dropdown , and user will select it not by entering in url.
@davidmejia9601
@davidmejia9601 3 жыл бұрын
you save my day bro... thanks a lot.....
@Codemycom
@Codemycom 3 жыл бұрын
Happy to help
@amangautam1779
@amangautam1779 2 жыл бұрын
thanks walter white!!
@Codemycom
@Codemycom 2 жыл бұрын
Ha!
@RyantheCanuckpirate
@RyantheCanuckpirate Жыл бұрын
Say my domain name.
@danielkraus5662
@danielkraus5662 4 жыл бұрын
Great videos! Please do one with adding subcategories for the categories or even a star rating system similar to the likes button.
@Codemycom
@Codemycom 4 жыл бұрын
Probably won't go that in depth in this basic course.
@danielkraus5662
@danielkraus5662 4 жыл бұрын
@@Codemycom ok
@letslearnui
@letslearnui 3 жыл бұрын
I tried the same process but I am not able to slugify the categories with two words. The category/categry-name does not load the posts Please help thanks
@omarmughrabi1419
@omarmughrabi1419 2 жыл бұрын
Thanks for the great tutorials, actually I am able to follow every concept explained in this series. But for this tutorial I am having a concern for applying slugify on spaces contained category and then replacing the dash later on with space for categories that might have dash already like "anti-bodies". Is there a way to have a user defined slugify character to be & or % or maybe both instead of -?! 😁
@el_bartomedia
@el_bartomedia 4 жыл бұрын
best video men!!!
@Codemycom
@Codemycom 4 жыл бұрын
Thanks!
@Kyotox04
@Kyotox04 4 жыл бұрын
You look like #Heisenberg from breaking bad. Thanks for the Slugify.
@Codemycom
@Codemycom 4 жыл бұрын
Ha!
@ashutoshrai323
@ashutoshrai323 3 жыл бұрын
Probably in 15-20 years..😂
@joeboyle732
@joeboyle732 4 жыл бұрын
Just in case anyone else runs into a problem here, if your categories have upper case letters at any point then slugify will convert them to lower case and the filter may not pick them up
@Codemycom
@Codemycom 4 жыл бұрын
That's easily changed...
@open-source-is-the-answer
@open-source-is-the-answer 4 жыл бұрын
@@Codemycom how do you do it the easiest way? should I replace Post.objects.filter... with some lambda expression to ignoring case when searching? or is it much simpler?
@dennismartin5455
@dennismartin5455 4 жыл бұрын
What if your category has hyphens and spaces in it, such as, "Brother-In-Law Advice"?
@Codemycom
@Codemycom 4 жыл бұрын
tinker around with it and find out :-p
@suvarneshkm4845
@suvarneshkm4845 4 жыл бұрын
Can you make a video on "how to use a api inside a django app! "
@Codemycom
@Codemycom 4 жыл бұрын
I've done several courses on that. Check the channel or codemy.com
@suvarneshkm4845
@suvarneshkm4845 4 жыл бұрын
@@Codemycom but I am not have enough money to spend so plz do the api part for me !
@dradrigapatrick
@dradrigapatrick 4 жыл бұрын
Slugify option doesnt work for me at all Any way i can solve it?
@Codemycom
@Codemycom 4 жыл бұрын
check your code for typos...things don't arbitrarily not work for some people, you have an error in your code
@miraccan00
@miraccan00 4 жыл бұрын
John I think you should research some KZbin Seo. I believe you will reach your goals
@Codemycom
@Codemycom 4 жыл бұрын
I helped invent the SEO industry lol I created one of the first SEO tools back in the late 90's called the Submission-Spider
@lenterahitam6519
@lenterahitam6519 3 жыл бұрын
How do you show the number of items in the model to the template, for example, the number of books in each category?
@saidsaid-nn1qk
@saidsaid-nn1qk 4 жыл бұрын
After adding "slugify" and replace function, when I try to go onto categories other than coding, it redirects to "sorry page doesn't exist. Is it only happening to me or is it the same with your code?
@Codemycom
@Codemycom 4 жыл бұрын
It's just you
@DavidLejeune77
@DavidLejeune77 3 жыл бұрын
Had the same error , check if you used capital letters somewhere in your category name
@hamzazahir1884
@hamzazahir1884 2 жыл бұрын
Does anyone knows how to stop the site from adding the SAME category name again which has already been added to the database? For example once the user adds a category named "cars" and the user enters the same category again instead of adding, It should tell the user that this category has already been included in database.
@haack79
@haack79 11 ай бұрын
if you just slugify the category when saving them you don't have to worry about adding slugify in all the other spots and then doing all that logic to replace - with ' ' except for title.
@Codemycom
@Codemycom 11 ай бұрын
sure, always a million different ways to do anything
@haack79
@haack79 11 ай бұрын
@@Codemycom true, thanks for this tutorial, its great.
@ulvidamirli2758
@ulvidamirli2758 4 жыл бұрын
Thank you for this beautiful video! I decided to go with django-autoslug package.. But every word I write in URL works, it doesn't give a 404 error. Looks like I'm missing something somewhere
@Codemycom
@Codemycom 4 жыл бұрын
Coolio
@nooobgamer01
@nooobgamer01 4 жыл бұрын
❤❤👍👍
@Codemycom
@Codemycom 4 жыл бұрын
:-)
@sambad8429
@sambad8429 3 жыл бұрын
what if some titles has - and others not?
@moiiin265
@moiiin265 4 жыл бұрын
Is there a way I can make category urls in foreign languages? I searched code "slug=modles.SlugField(allow_unicode=True)" but still don't know how to apply this in my models.py and urls.py
@miraccan00
@miraccan00 4 жыл бұрын
is not correct? please. when ı enter into my category it's empty
@Codemycom
@Codemycom 4 жыл бұрын
if you named your model something else besides category....
@anonymousghost5384
@anonymousghost5384 3 жыл бұрын
Iuse vuejs to categorize posts without reload page
@trippy_b
@trippy_b 4 жыл бұрын
and what would be a URL pattern for this, please?
@leosoltys4353
@leosoltys4353 4 жыл бұрын
Thank you for this lesson John! But after 06:36 still its possible to reach 127.0.0.1:8000/category/coding tutorials/ (with space) How we can make 127.0.0.1:8000/category/coding tutorials/ this page deactive?
@plusk343
@plusk343 4 жыл бұрын
URLs don't contain spaces.
@dipeshmandanka5607
@dipeshmandanka5607 3 жыл бұрын
+1
@Morimove
@Morimove Жыл бұрын
slugigy all changes the captital letters into lowecase
@ilijataseski6855
@ilijataseski6855 3 жыл бұрын
If a category is Hiking and not hiking. you need ... |slugify|capfirst .....
@mustafaongun8548
@mustafaongun8548 Жыл бұрын
Thank you Walter White
@Codemycom
@Codemycom Жыл бұрын
lol
@gamerstrim
@gamerstrim 4 жыл бұрын
Please create video course about discord bot with python
@Codemycom
@Codemycom 4 жыл бұрын
That's not really my thing, sorry.
@diallomamadoudioulde8252
@diallomamadoudioulde8252 4 жыл бұрын
Hello thanks you for the tutorials ! Please how can I display videos saved in my database on my Django Website ? Thanks you in advance.
@Codemycom
@Codemycom 4 жыл бұрын
People generally don't save videos in databases.
@diallomamadoudioulde8252
@diallomamadoudioulde8252 4 жыл бұрын
@@Codemycom okay so how I can upload and read videos on my website ?
@Codemycom
@Codemycom 4 жыл бұрын
@@diallomamadoudioulde8252 Most people host videos on sites like vimeo, or youtube, and just paste embed code onto their website to play the videos.
@diallomamadoudioulde8252
@diallomamadoudioulde8252 4 жыл бұрын
@@Codemycom OK thanks anyway. I can't do it so it's too complicated I think.
How To Add Blog Category Navbar Links - Django Blog #15
20:28
Codemy.com
Рет қаралды 23 М.
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 249 М.
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН
人是不能做到吗?#火影忍者 #家人  #佐助
00:20
火影忍者一家
Рет қаралды 20 МЛН
How To Restrict Who Can Make Blog Posts - Django Blog #17
14:48
Codemy.com
Рет қаралды 18 М.
How To Upload Images With Django - Django Blog #26
17:59
Codemy.com
Рет қаралды 79 М.
Blog Category Pages - Django Blog #13
16:13
Codemy.com
Рет қаралды 29 М.
Create Blog Like Button - Django Blog #18
19:35
Codemy.com
Рет қаралды 54 М.
Add Blog Categories - Django Blog #12
20:10
Codemy.com
Рет қаралды 43 М.
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН