Django Slug (Slugify URL)

Simple slugify URL in Django.
Official docs here.

Slugify URL

Step 1: Preparation, Create Django Project, Initial Migration
create virtualenv: virtualenv venv
start virtualenv: venv/Scripts/activate
install Django in virtualenv: pip install django==3.2
Create Django: django-admin startproject myproject
Go to myproject folder: cd myproject
Initial Migration: python migrate

Step 2: Create Django Apps
Create apps: python startapp myapp
Add myapp to INSTALLED_APPS in myproject/

INSTALLED_APPS in myproject/

Step 3: Setup Templates
Create folder templates in myapp

Add template directory in TEMPLATES parameter in myproject/

Step 4: Add Model, Register Model in Django Admin, Makemigrations and Migrate
Add Model in myapp/


Register Model in myapp/


Make migrations: python makemigrations
Migrate: python migrate

Step 5: Create HTML Files in myapp/templates Folder
Create myapp/templates/book.html


Step 6: Update Views
Update myapp/ Add Function Based View method that render book.html.


Step 7: Setup URL
Create myapp/


Update myproject/


Step 8: Create Superuser
Create superuser: python createsuperuser
Type username, email, password and retype password

Step 9: Run Server and Testing
Run Server: python runserver
Try login, add some books.

Add book with prepopulated_fields for slug




Software Engineer, Indonesia

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store