Badr Erraji
Badr Erraji

Reputation: 217

django no module named 'settings'

i inherited a python project where django is used. for my devs, i needed the transaction module of django.

so i went to 'P:\file\ourLibrary\server\config\settings.py' and updated the

**DATABASES = {
    'default': { filled infos }**

then in Powershell i set the ENV_VARIABLE DJANGO_SETTINGS_MODULE to the path specified before

i then tried to use the function that uses the @transaction.atomic but i had the folowing error

> You must either define the **environment variable
> DJANGO_SETTINGS_MODULE** or call **settings.configure()** before
> accessing settings.

which i don't understand because i already setted it.

i found various posts in StackOverflow that suggest to use

import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE','P:\file\ourLibrary\server\config\settings')

but now when i use the @transaction function i got

ModuleNotFoundError: No module named **'P:\file\ourLibrary\server\config\settings'**

what am i doing wrong here?

thank you for your help,

Upvotes: 0

Views: 970

Answers (1)

Bhavya Peshavaria
Bhavya Peshavaria

Reputation: 361

The path needs to be set in terms of the Python import path. Try

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ourLibrary.server.config.settings')

Upvotes: 1

Related Questions