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.
"""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
if not self.page_id:
self.page_name = slugify(self.page_title)
Here is the 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
Assertions is one of the most advanced Exception Handling technique used in python by using the Assert statement,we can create debug message,if anything logically end up with an error.If anything fails logically AssertionError will display and end the process. here we will check assertion error python
When we are working with automatic car project their is a situation of fuel tank is empty that time we have to stop all process and stop the vehicle with an error message “no fuels”
See the syntax here
assert Expression[, Arguments]
Create a fuel.py file with below function
assert (fuel > 0),"Sorry no fuel in the system"
Run from command prompt
we know that Django is one of the most popular framework in python.we already discussed how to install a Djnago frame work in windows .Now we have installed Djnago framework in our system.We read Djnago provide build-in admin panel automaticaly ,so our question is what is the user name and password for admin Django,here am going to explain How to create new admin user in Django.
In Django default admin url is http://127.0.0.1:8000/admin/login/?next=/admin/,when you type http://127.0.0.1:8000/admin/login/?next=/admin/ in your browser ,you will get below User Interface
To Login above admin side we need admin user name and password ,see here how to create new admin user in Django
python manage.py createsuperuser
It will ask you new admin user info for your Djnago dashboard
When an running my Django python application am getting an error “Module Not found error no module named celery”. as the error says no module celery is not their in system.Since module named celery is not their with sytem we are getting an error “Module Not found error no module named celery in Python Django”.To solve this error “Module Not found error no module named celery in Python Django”, we have to install celery module in your system, to install celery we have to use PIP command.if pip is not installed with your first you to install pip after run below commands .
Install celery module in Django python
# pip install celery