Answer the question
In order to leave comments, you need to log in
How to fix error: django.core.exceptions.ImproperlyConfigured?
Task: test the script.
The script has an import of models and access to them.
When I run the file I get this.
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
The file itself:
from myproject_app.models import *
from django.db.models import Max
from myproject.settings import BASE_DIR
# ---------------------------------------------------------------
# То что нашел на Stack Owerflow
import os
import sys
from django.conf import settings
settings.configure()
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
sys.path.append(BASE_DIR)
# ---------------------------------------------------------------
class Stripes:
# Здесь в методах обращение к моделям.
if __name__ == '__main__':
# Здесь тестирую
Answer the question
In order to leave comments, you need to log in
Try doing settings.configure() before importing the models. If you want to do everything in one file take a look at https://github.com/readevalprint/mini-django/blob/...
You can also set an environment variable
# win
set DJANGO_SETTINGS_MODULE="myproject.settings"
# shell
export DJANGO_SETTINGS_MODULE="myproject.settings"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question