Creating a Unique Slug for your django app

Words
152
Reading
1 min
Listen
Play
9y

This Snippet is used for creating Unique slugs for Django Web Applications.

In building a web application, it is usually common to store contents in the database and a slug is generated based on the title of the content.

Problem

Two posts having the same title would always generate an error like this below.
Screen Shot 2017-12-27 at 11.37.26 PM.png

This requires you to change the title of your post.

Solution

The unique slug snippet generates a unique slug even if two titles are the same. This eliminates the hassle of changing the title of your post.

This works by first checking the database if the slug exists. if it exists, it generates some random character and adds it to the end of the slug.

This ensures that no two titles have the same slug. This helps the users have a better experience with your web application.

Github: https://github.com/Rhotimee/Unique-Slug-Generator
Screen Shot 2017-12-28 at 12.00.16 AM.png



Posted on Utopian.io - Rewarding Open Source Contributors

Creating a Unique Slug for your django app | Ecency