Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between SlugField() vs CharField() in Django models

So, in my Django projects, I made my model to be like the following

class Store(models.Model):
    domainKey = models.CharField()

I had the above to make each store has its own domain like the following

www.domain.com/my-name-is-django

Anyway, it was perfectly working fine. But, I just found out SlugField() which is used for the same purpose as what I did in above. My question is why we need to use SlugField() because I implemented the same thing without SlugField(). Is there its own any feature that CharField() doesn't have?

like image 445
Jae P. Avatar asked Sep 03 '25 01:09

Jae P.


1 Answers

A slug is a string without special characters, in lowercase letters and with dashes instead of spaces, optimal to be used in URLs. An example of slug could be:

 example/this-is-a-slug/150

you can look for more information here Documentation django slug

CharField has max_length of 255 characters , and accept special characters.

About CharField Here

like image 160
Diego Avila Avatar answered Sep 13 '25 02:09

Diego Avila