Slugs for your blog
Posted on
by Kevin FoongSlugs are great for SEO and humans alike. For example, "/post_detail/vue-spa-and-flask-together" looks much better than "/post_detail/8".
In Python it is very easy to create slugs from the title of your blog post. Just use the excellent python-slugify library. The command is simple.
slugify("Vue Spa and Flask Together")
This will give you the slug "vue-spa-and-flask-together"
Now in order to use the slug you will need to store it in your database. As you will be using the slug to query the database instead of the post id, you will also need to ensure that the slug is unique before saving to your database.
For the full source code of how this can be done view my Github page.