Django NameError: name 'os' is not defined

Published On: 12/08/2022 | Category: Django

Hi Dev,

This tutorial will give you example of django os modual not found. this example will help you django nameerror: name 'os' is not defined. let’s discuss about name os is not defined after import. this example will help you os error in django.

So, if you've started or install a new Django 3.1+ project and are using older articles or guides, it's likely to come across the following error on getting generate to this error:

Django 3.1, the startproject command generates a settings.py file that imports pathlib rather than os on the top line.

So let quick fix is to import os at the top of your settings.py file:

Solution: settings.py
import os # new
from pathlib import Path

I Hope It will help you....