NameError name slugify is not defined Django error

Most of the case When you tried to add a slug keyword for page model you will get error NameError: name ‘slugify’ is not defined Django error.Here we are discussing how to solve “NameError: name ‘slugify’ is not defined Django error”

Here is the model

from django.db import models

# Create your models here.
class page(models.Model):
 """Model representing a book (but not a specific copy of a book)."""
 
 page_id = models.AutoField(primary_key=True)
 
 page_title = models.CharField(max_length=200)

 author_name = models.CharField(max_length=100)
 
 page_content = models.TextField(max_length=1000, help_text='Enter your page content')
 
 page_name = models.SlugField(editable=False) # hide from admin

 def save(self):
 if not self.page_id:
 self.page_name = slugify(self.page_title)

 super(page, self).save()

Here is the error

“NameError: name ‘slugify’ is not defined Django error”

 

NameError name slugify is not defined Django error

How to Solve it

Step install  python-slugify module

# pip install python-slugify

Include slugify module in your model
 from slugify import slugify

NameError name slugify is not defined Django error 2

 

My Thought

Your email address will not be published. Required fields are marked *

Our Tool : hike percentage calculator