Estoy creando un proyecto en Django con una app llamada Blog, configuro el archivo settings.py
pero estoy teniendo problemas con la SECRET_KEY
, no sé por qué me sale un error de que no puedo contener esta llave vacia. Mi configuración es:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'blog',
'USER': 'xxxx',
'PASSWORD': 'xxxx',
'HOSTNAME': '',
'PORT': '',
}
}
SECRET_KEY = '18x&q4kb9oa!qz-7wg(nk#0%w-=49$ylj1gtn1n6^e0pe@@8ge'
Toda la configuración resulta estar bien, contengo la SECRET_KEY
, pero al momento de aplicar las migraciones para la configuración inicial de Django, me sale este error:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 190, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 40, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 19, in <module>
from django.db.migrations.autodetector import MigrationAutodetector
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/autodetector.py", line 13, in <module>
from django.db.migrations.questioner import MigrationQuestioner
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/questioner.py", line 12, in <module>
from .loader import MIGRATIONS_MODULE_NAME
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 10, in <module>
from django.db.migrations.recorder import MigrationRecorder
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 9, in <module>
class MigrationRecorder(object):
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 23, in MigrationRecorder
class Migration(models.Model):
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 24, in Migration
app = models.CharField(max_length=255)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 1081, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 161, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 113, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
Estuve averiguando alguna solución y resulta que en algunos blogs hablan sobre como si modificaste el nombre del proyecto debes de configurar el manage.py
como sigue:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite_project.settings")
Pero la configuración está bien hecha, no sé realmente por qué obtengo este error.
python manage.py shell
, luego importas tus configuraciones confrom django.conf import settings
y finalmente imprimes conprint settings.SECRET_KEY
, ¿qué te sale?SECRET_KEY