Solved

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

Posted on 2015-01-20
12
511 Views
Last Modified: 2015-02-23
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',
0
Comment
Question by:lz7cjc
  • 7
  • 4
12 Comments
 
LVL 16

Accepted Solution

by:
gelonida earned 500 total points
ID: 40559685
can you add a small line in your settings.py file just to be sure, that you really import the correct settings.py

add following line immediately AFTER the line, that sets the SECRET_KEY value
print("SECRET_KEY = %s", SECRET_KEY) ; import time ; time.sleep(3)


when starting your command, do you see the output value?
does the script pause for three seconds before failing later?
0
 

Author Comment

by:lz7cjc
ID: 40560216
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.
0
 
LVL 16

Expert Comment

by:gelonida
ID: 40560237
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

0
 

Author Comment

by:lz7cjc
ID: 40560251
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
0
 
LVL 16

Expert Comment

by:gelonida
ID: 40560685
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

1
 

Author Comment

by:lz7cjc
ID: 40561444
I get ImportError: No module named hideyhole.settings. How can that be? The settings file absolutely exists?!
0
Save on storage to protect fatherhood memories

You're the dad who has everything. This Father's Day, make sure your family memories are protected. My Passport Ultra has automatic backup and password protection to keep your cherished photos and videos safe. With up to 3TB, you have plenty of room to hold the adventures ahead.

 
LVL 16

Expert Comment

by:gelonida
ID: 40561446
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?
0
 

Author Comment

by:lz7cjc
ID: 40561454
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
0
 

Assisted Solution

by:lz7cjc
lz7cjc earned 0 total points
ID: 40561621
I might be getting somewhere  - Pycharm is creating new files rather than importing my projects that I created at the command line... will continue on this clean sheet path and see how far it takes me
0
 

Author Comment

by:lz7cjc
ID: 40561646
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
0
 

Author Closing Comment

by:lz7cjc
ID: 40570220
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.
0
 

Expert Comment

by:Sat
ID: 40625258
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Set up notificataion or alert from a website 2 63
cookies analysis tools 2 73
Need help with python script - Insert data from user input into MS SQL 35 67
yara deployment 8 33
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now