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\documen ts\coding\ websites_g o_here\hid eyhole> 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-pack ages\djang o\core\man agement\__ init__.py" , line 385, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-pack ages\djang o\core\man agement\__ init__.py" , line 377, in execute
self.fetch_command(subcomm and).run_f rom_argv(s elf.argv)
File "C:\Python27\lib\site-pack ages\djang o\core\man agement\__ init__.py" , line 238, in fetch_command
klass = load_command_class(app_nam e, subcommand)
File "C:\Python27\lib\site-pack ages\djang o\core\man agement\__ init__.py" , line 41, in load_command_class
module = import_module('%s.manageme nt.command s.%s' % (app_name, name))
File "C:\Python27\lib\importlib \__init__. py", line 37, in import_module
__import__(name)
File "C:\Python27\lib\site-pack ages\djang o\core\man agement\co mmands\syn cdb.py", line 5, in <module>
from django.contrib.auth import get_user_model
File "C:\Python27\lib\site-pack ages\djang o\contrib\ auth\__ini t__.py", line 7, in <module>
from django.middleware.csrf import rotate_token
File "C:\Python27\lib\site-pack ages\djang o\middlewa re\csrf.py ", line 14, in <module>
from django.utils.cache import patch_vary_headers
File "C:\Python27\lib\site-pack ages\djang o\utils\ca che.py", line 26, in <module>
from django.core.cache import caches
File "C:\Python27\lib\site-pack ages\djang o\core\cac he\__init_ _.py", line 34, in <module>
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "C:\Python27\lib\site-pack ages\djang o\conf\__i nit__.py", line 46, in __getattr__
self._setup(name)
File "C:\Python27\lib\site-pack ages\djang o\conf\__i nit__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python27\lib\site-pack ages\djang o\conf\__i nit__.py", line 115, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.Imp roperlyCon figured: 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.contenttyp es',
'django.contrib.sessions',
'django.contrib.messages',
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.m iddleware. SessionMid dleware',
'django.middleware.common. CommonMidd leware',
'django.middleware.csrf.Cs rfViewMidd leware',
'django.contrib.auth.middl eware.Auth entication Middleware ',
'django.contrib.auth.middl eware.Sess ionAuthent icationMid dleware',
'django.contrib.messages.m iddleware. MessageMid dleware',
'django.middleware.clickja cking.XFra meOptionsM iddleware' ,
when i run python manage.py syncdb I get the following error:
PS C:\Users\nicka_000\documen
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(
File "C:\Python27\lib\site-pack
utility.execute()
File "C:\Python27\lib\site-pack
self.fetch_command(subcomm
File "C:\Python27\lib\site-pack
klass = load_command_class(app_nam
File "C:\Python27\lib\site-pack
module = import_module('%s.manageme
File "C:\Python27\lib\importlib
__import__(name)
File "C:\Python27\lib\site-pack
from django.contrib.auth import get_user_model
File "C:\Python27\lib\site-pack
from django.middleware.csrf import rotate_token
File "C:\Python27\lib\site-pack
from django.utils.cache import patch_vary_headers
File "C:\Python27\lib\site-pack
from django.core.cache import caches
File "C:\Python27\lib\site-pack
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "C:\Python27\lib\site-pack
self._setup(name)
File "C:\Python27\lib\site-pack
self._wrapped = Settings(settings_module)
File "C:\Python27\lib\site-pack
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.Imp
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.contenttyp
'django.contrib.sessions',
'django.contrib.messages',
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.m
'django.middleware.common.
'django.middleware.csrf.Cs
'django.contrib.auth.middl
'django.contrib.auth.middl
'django.contrib.messages.m
'django.middleware.clickja
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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:
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
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("DJA NGO_SETTIN GS_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
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJA
from django.core.management import execute_from_command_line
execute_from_command_line(
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?
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__"
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\documen ts\coding\ websites_g o_here\hid eyhole
when startin manage.py, then
settings.py should be located in
C:\Users\nicka_000\documen ts\coding\ websites_g o_here\hid eyhole\hid eyhole\set tings.py
Further you MUST be sure, that the following file exists:
C:\Users\nicka_000\documen ts\coding\ websites_g o_here\hid eyhole\hid eyhole\__i nit__.py
Which version of Django are you using and how did you create your project?
when startin manage.py, then
settings.py should be located in
C:\Users\nicka_000\documen
Further you MUST be sure, that the following file exists:
C:\Users\nicka_000\documen
Which version of Django are you using and how did you create your project?
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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-p ackages/dj ango/core/ management /__init__. py", line 469, in execute_manager
utility.execute()
File "/usr/lib/python2.7/site-p ackages/dj ango/core/ management /__init__. py", line 392, in execute
self.fetch_command(subcomm and).run_f rom_argv(s elf.argv)
File "/usr/lib/python2.7/site-p ackages/dj ango/core/ management /__init__. py", line 272, in fetch_command
klass = load_command_class(app_nam e, subcommand)
File "/usr/lib/python2.7/site-p ackages/dj ango/core/ management /__init__. py", line 77, in load_command_class
module = import_module('%s.manageme nt.command s.%s' % (app_name, name))
File "/usr/lib/python2.7/site-p ackages/dj ango/utils /importlib .py", line 35, in import_module
__import__(name)
File "/usr/lib/python2.7/site-p ackages/dj ango/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-p ackages/dj ango/core/ management /sql.py", line 9, in <module>
from django.db import models
File "/usr/lib/python2.7/site-p ackages/dj ango/db/__ init__.py" , line 11, in <module>
if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/usr/lib/python2.7/site-p ackages/dj ango/conf/ __init__.p y", line 53, in __getattr__
self._setup(name)
File "/usr/lib/python2.7/site-p ackages/dj ango/conf/ __init__.p y", line 48, in _setup
self._wrapped = Settings(settings_module)
File "/usr/lib/python2.7/site-p ackages/dj ango/conf/ __init__.p y", line 152, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.Imp roperlyCon figured: 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-p
utility.execute()
File "/usr/lib/python2.7/site-p
self.fetch_command(subcomm
File "/usr/lib/python2.7/site-p
klass = load_command_class(app_nam
File "/usr/lib/python2.7/site-p
module = import_module('%s.manageme
File "/usr/lib/python2.7/site-p
__import__(name)
File "/usr/lib/python2.7/site-p
from django.core.management.sql
File "/usr/lib/python2.7/site-p
from django.db import models
File "/usr/lib/python2.7/site-p
if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/usr/lib/python2.7/site-p
self._setup(name)
File "/usr/lib/python2.7/site-p
self._wrapped = Settings(settings_module)
File "/usr/lib/python2.7/site-p
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.Imp
ASKER
PS C:\Users\nicka_000\documen
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(
File "C:\Python27\lib\site-pack
utility.execute()
File "C:\Python27\lib\site-pack
self.fetch_command(subcomm
File "C:\Python27\lib\site-pack
klass = load_command_class(app_nam
File "C:\Python27\lib\site-pack
module = import_module('%s.manageme
File "C:\Python27\lib\importlib
__import__(name)
File "C:\Python27\lib\site-pack
from django.contrib.auth import get_user_model
File "C:\Python27\lib\site-pack
from django.middleware.csrf import rotate_token
File "C:\Python27\lib\site-pack
from django.utils.cache import patch_vary_headers
File "C:\Python27\lib\site-pack
from django.core.cache import caches
File "C:\Python27\lib\site-pack
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "C:\Python27\lib\site-pack
self._setup(name)
File "C:\Python27\lib\site-pack
self._wrapped = Settings(settings_module)
File "C:\Python27\lib\site-pack
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.Imp