0

When i try to run django, i am getting error django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty , there is already SECRET_KEY exist in settings.py file SECRET_KEY = 'g1tmo148kxtw#^obw&apoms%n=&4g+2qi1ssuc$v3(fig-he4u' still i am getting the error, can anyone please help me how to resolve this issue ?

settings.py

import django
django.setup()

import os


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'g1tmo148kxtw#^obw&apoms%n=&4g+2qi1ssuc$v3(fig-he4u'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Nikul Panchal
  • 1,542
  • 3
  • 35
  • 58

1 Answers1

1

Just remove the django.setup() on your setting.py file and you're good to go.

To clarify it more, when django.setup() is called, it should already have a settings file, and therefore a SECRET_KEY; So it raise such an error.

Pedram Parsian
  • 3,750
  • 3
  • 19
  • 34
  • If i removed it then getting this error : django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. – Nikul Panchal Nov 29 '19 at 08:23
  • You should include the list of your `INSTALLED_APPS` in the settings file, I think that's the cause of problem. btw why you're not using the django's default setting template? – Pedram Parsian Nov 29 '19 at 08:25
  • INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', #'django.contrib.contenttypes', 'django.contrib.contenttypes.fields.GenericForeignKey', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'trialrisk', ] this app is already in settings.py file – Nikul Panchal Nov 29 '19 at 08:28
  • I think the problem is about `django.contrib.contenttypes.fields.GenericForeignKey`. Try removing it; Because you can't load a **field** from `django.contrib.contenttypes` as the `django.contrib.contenttypes` itself hasn't fully loaded. – Pedram Parsian Nov 29 '19 at 08:29
  • I removed it and getting this error : ImportError: cannot import name 'generics' – Nikul Panchal Nov 29 '19 at 08:36
  • Use this: `INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'trialrisk', ]`; namely: remove `django.contrib.contenttypes.fields.GenericForeignKey` and uncomment `django.contrib.contenttypes` – Pedram Parsian Nov 29 '19 at 08:38
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/203305/discussion-between-nikul-panchal-and-pedram-parsian). – Nikul Panchal Nov 29 '19 at 08:39