▶️ 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
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,
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.
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?
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?
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
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.
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?
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 %}
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.
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
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.
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 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?
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 -?! 😁
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?
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
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('-', ' ')
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!
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.
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
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?
Im feeling rather sluggified after smashing through 14 Django tutorials.. 5 more to goo!! Learning lots here thanks mate!
ha fun
▶️ 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
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})
Thanks! This fixed my "This page is not valid." error.
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,
the same with me, and if you try the url with '-' the title delete the space between words
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 }}
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
I appreciate that!
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.
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?
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?
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
good job codemy
very nice. 👍👍👍
Thank you! 👍
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.
*Congratulations 40 K Subs*
Thanks!
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?
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 %}
Thanks for all these vids man! Really helpfull!
Glad you like them!
Hi I like your videos I have difficulty with english but I understand that very well
I realized that when the category is upper-case, it can be a problem
Glad you like them
@@htshongany4969 You could write some code to change everything to lowercase if you have a problem with it
I'm looking for a solution
I tried yesterday and I've had some unexpected behavior. I plan to try again today.
Great job man, loved it
Thanks a lot!
you save my day bro... thanks a lot.....
Happy to help
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.
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
Slugify option doesnt work for me at all
Any way i can solve it?
check your code for typos...things don't arbitrarily not work for some people, you have an error in your code
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.
categories will be listed in the dropdown , and user will select it not by entering in url.
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
That's easily changed...
@@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?
Great videos! Please do one with adding subcategories for the categories or even a star rating system similar to the likes button.
Probably won't go that in depth in this basic course.
@@Codemycom ok
How do you show the number of items in the model to the template, for example, the number of books in each category?
What if your category has hyphens and spaces in it, such as, "Brother-In-Law Advice"?
tinker around with it and find out :-p
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 -?! 😁
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?
It's just you
Had the same error , check if you used capital letters somewhere in your category name
thanks walter white!!
Ha!
Say my domain name.
best video men!!!
Thanks!
You look like #Heisenberg from breaking bad. Thanks for the Slugify.
Ha!
Probably in 15-20 years..😂
what if some titles has - and others not?
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
Check your code for errors
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('-', ' ')
@@samuellee1431 thanks this saved my time
@@samuellee1431 Thank you so much you save my time
@@samuellee1431 thanks a lot dood.. It helped me alot....
is not correct? please. when ı enter into my category it's empty
if you named your model something else besides category....
Iuse vuejs to categorize posts without reload page
and what would be a URL pattern for this, please?
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!
Could be...play around with it and see.
Filter using __iexact which takes all the arguments ignoring upper and lower case
For example: Post.objects.filter(category__iexact=cats)
@@joseparedes4260 Thanks alot man! This had me stumped lol
@@joseparedes4260 thanks buddy it helped
@@joseparedes4260 Worked for me too. Thank you! :)
Can you make a video on "how to use a api inside a django app! "
I've done several courses on that. Check the channel or codemy.com
@@Codemycom but I am not have enough money to spend so plz do the api part for me !
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.
sure, always a million different ways to do anything
@@Codemycom true, thanks for this tutorial, its great.
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
Coolio
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?
URLs don't contain spaces.
+1
John I think you should research some TH-cam Seo. I believe you will reach your goals
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
If a category is Hiking and not hiking. you need ... |slugify|capfirst .....
slugigy all changes the captital letters into lowecase
❤❤👍👍
:-)
Hello thanks you for the tutorials ! Please how can I display videos saved in my database on my Django Website ? Thanks you in advance.
People generally don't save videos in databases.
@@Codemycom okay so how I can upload and read videos on my website ?
@@diallomamadoudioulde8252 Most people host videos on sites like vimeo, or youtube, and just paste embed code onto their website to play the videos.
@@Codemycom OK thanks anyway. I can't do it so it's too complicated I think.
Thank you Walter White
lol
Please create video course about discord bot with python
That's not really my thing, sorry.