catch_me catch_me - 3 months ago 14
Python Question

Secret key is there though it is saying no secret key in django

When i'm running python manage.py runserver or python manage.py migrate. I'm getting these errors

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 190, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 40, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 14, in <module>
from django.db.migrations.executor import MigrationExecutor
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 6, in <module>
from .loader import MigrationLoader
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 10, in <module>
from django.db.migrations.recorder import MigrationRecorder
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 9, in <module>
class MigrationRecorder(object):
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 23, in MigrationRecorder
class Migration(models.Model):
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 24, in Migration
app = models.CharField(max_length=255)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1081, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 161, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/conf/__init__.py", line 113, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.


This is my development settings

"""
Django settings for kgecweb project.

Generated by 'django-admin startproject' using Django 1.8.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

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/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'my_secret key here'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
#DEBUG = False

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'administration',
'stdimage',
'dept',
'trplc', # Training and Placement app
'faculty',
'student',
'hostels',
'nkn',
'clibrary',
'page',
'contact'




)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'kgecweb.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, '../templates'), ],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'kgecweb.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
#'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.mysql'),
'USER': 'root',
'PASSWORD': '713331',
'HOST': '192.168.33.19',
'PORT': '3306',
#'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Kolkata'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATICFILES_DIRS = (os.path.join(BASE_DIR, "../static"),)


#STATIC_ROOT= os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

MEDIA_ROOT = os.path.join(BASE_DIR, '../media')
MEDIA_URL = '/media/'


I also have made the sql command for initializing database and secret key is also not empty here. Though it keep on saying. i don't know how to tackle this.

Answer

Try:

python manage.py runserver --settings=your_project.your_real_settting.py

I guess your didn't use the build-in setting.py or you rename it or make a directory to handle different settings.py.

Comments