![](/img/trans.png)
[英]getting error : django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty in django
[英]Python django : django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty
我正在嘗試使用ubuntu服務器啟動django-app
/opt$ sudo python peace/src/manage.py runserver
我收到“ django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
”的錯誤django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
我可以在Windows的開發環境Eclipse IDE中啟動相同的應用程序!!
我的文件夾結構> /opt/peace/src/manage.py
設置文件夾結構> /opt/peace/src/peace/settings/
manage.py:-
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "peace.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
請指教,
完整的錯誤日志
ubuntu@ip-172-31-19-246:/opt$ sudo python peace/src/manage.py runserver
Traceback (most recent call last):
File "peace/src/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/runserver.py", line 14, in <module>
from django.db.migrations.executor import MigrationExecutor
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 6, in <module>
from .loader import MigrationLoader
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.
.. /settings/base.py
import environ
env = environ.Env()
# Ideally move env file should be outside the git repo
# i.e. BASE_DIR.parent.parent
env_file = join(dirname(__file__), 'local.env')
if exists(env_file):
environ.Env.read_env(str(env_file))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
# Raises ImproperlyConfigured exception if SECRET_KEY not in os.environ
SECRET_KEY = env('SECRET_KEY')
local.env
DEBUG=True
# syntax: DATABASE_URL=psql://username:password@127.0.0.1:8458/database
DATABASE_URL=sqlite:///db.sqlite3
SECRET_KEY="v(jkz$=0+nj38pmf%iqddjok47zcgt+h%9*6ehn=2vbbj3%vj&"
看來您未正確引用DJANGO_SETTINGS_MODULE
。 在您的manage.py中,您僅指向peace.settings
,但是您可能需要指向其中的模塊之一,例如, peace.settings.base
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.