Solved

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

Posted on 2015-01-20
12
464 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…

762 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

23 Experts available now in Live!

Get 1:1 Help Now