Link to home
Start Free TrialLog in
Avatar of lz7cjc
lz7cjc

asked on

Can't set up CMS in Django - asking for secret_key which is set

Hi
when i run python manage.py syncdb I get the following error:
PS C:\Users\nicka_000\documents\coding\websites_go_here\hideyhole> python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 238, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 41, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py", line 5, in <module>
    from django.contrib.auth import get_user_model
  File "C:\Python27\lib\site-packages\django\contrib\auth\__init__.py", line 7, in <module>
    from django.middleware.csrf import rotate_token
  File "C:\Python27\lib\site-packages\django\middleware\csrf.py", line 14, in <module>
    from django.utils.cache import patch_vary_headers
  File "C:\Python27\lib\site-packages\django\utils\cache.py", line 26, in <module>
    from django.core.cache import caches
  File "C:\Python27\lib\site-packages\django\core\cache\__init__.py", line 34, in <module>
    if DEFAULT_CACHE_ALIAS not in settings.CACHES:
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 46, in __getattr__
    self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 115, in __init__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

However the secret_key is set up in settings.py:

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

I am trying to set up the CMS screens so have just identified installed apps and middleware in the settings page:
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
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',
ASKER CERTIFIED SOLUTION
Avatar of gelonida
gelonida
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lz7cjc
lz7cjc

ASKER

no i saw nothing different with that line of code inserted
PS C:\Users\nicka_000\documents\coding\websites_go_here\hideyhole> python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 238, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 41, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py", line 5, in <module>
    from django.contrib.auth import get_user_model
  File "C:\Python27\lib\site-packages\django\contrib\auth\__init__.py", line 7, in <module>
    from django.middleware.csrf import rotate_token
  File "C:\Python27\lib\site-packages\django\middleware\csrf.py", line 14, in <module>
    from django.utils.cache import patch_vary_headers
  File "C:\Python27\lib\site-packages\django\utils\cache.py", line 26, in <module>
    from django.core.cache import caches
  File "C:\Python27\lib\site-packages\django\core\cache\__init__.py", line 34, in <module>
    if DEFAULT_CACHE_ALIAS not in settings.CACHES:
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 46, in __getattr__
    self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 115, in __init__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
Just to be sure:

The script did NOT  print out the key  and pause for a 3 seconds before failing???

this would mean, that the settings.py file is not at all imported.

Two things you can try:
could you open manage.py and copy th4e contents to here (manage.py should be just a little more than 10 lines of code)

could you also type following command in the DOS prompt in which you  tried to start django:
set DJANGO_SETTINGS_MODULE

Open in new window

Avatar of lz7cjc

ASKER

correct there was no pause and nothing printed to screen

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hideyhole.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)


I ran the line of code and got no errors but no output
Well let's try following.

use the cmd window where you did try to start the python command and enter following line. What do you get as output?

python -c "import hideyhole.settings ; print hideyhole.settings.__file__"

Open in new window

Avatar of lz7cjc

ASKER

I get ImportError: No module named hideyhole.settings. How can that be? The settings file absolutely exists?!
If you are in the directory C:\Users\nicka_000\documents\coding\websites_go_here\hideyhole
when startin manage.py, then
settings.py should be located in
C:\Users\nicka_000\documents\coding\websites_go_here\hideyhole\hideyhole\settings.py
Further you MUST be sure, that the following file exists:
C:\Users\nicka_000\documents\coding\websites_go_here\hideyhole\hideyhole\__init__.py

Which version of Django are you using and how did you create your project?
Avatar of lz7cjc

ASKER

Django 1.7.2
django-admin startproject hideyhole
python manage.py startapp daypass

See attached for file structure - this looks the same as what you outline. I am wondering if I should just use a new project I set up last night to play around with the CMS. This seems to be working ok, so it might be a quicker more pragmatic approach?
Screenshot-2015-01-21-08.43.49.png
Screenshot-2015-01-21-08.44.25.png
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lz7cjc

ASKER

ok so in my new set up I have successful run the print("SECRET_KEY = %s", SECRET_KEY) ; import time ; time.sleep(3) command and the secret key is displayed... i also managed to successfully run set DJANGO_SETTINGS_MODULE

So this one is resolved - it was the way in which Pycharm was setting up the project... so will close this question which leaves us with the encoding issue (which I still get) and will pick that up on the other thread

thanks
Avatar of lz7cjc

ASKER

The fact that the secret_key wasn't displaying indicated there was another settings.py file somewhere. After some investigation it turned out this was because Pycharm was creating its own project rather than importing the files into a new project.
I am trying to install graphite on my linux machine. when i run python manage.py syncdb, i am getting the error "The SECRET_KEY setting must not be empty.".
I have django 1.5.12 on RHEL 7

in my setup, i could not get any SECRET_KEY on setting.py file. Then i manually entered a SECRET_KEY and I tried the below code and its printing the key and pause for a 3 seconds before failing.

print("SECRET_KEY = %s", SECRET_KEY) ; import time ; time.sleep(3)

error:
Traceback (most recent call last):
  File "manage.py", line 13, in <module>
    execute_manager(settings)
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 469, in execute_manager
    utility.execute()
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/usr/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
    from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
  File "/usr/lib/python2.7/site-packages/django/core/management/sql.py", line 9, in <module>
    from django.db import models
  File "/usr/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
    if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
    self._setup(name)
  File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 152, in __init__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.