Solved

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

Posted on 2015-01-20
12
538 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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
 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Command Line in Python 16 68
site launch date and last modified date 3 94
Difference of import usage in Python 1 68
How to generate a random directed graph 5 63
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

810 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