密匙在那里,尽管它在djang中说没有密匙

2024-04-27 12:24:52 发布

您现在位置:Python中文网/ 问答频道 /正文

当我运行python时管理.pyrunserver或python管理.py迁移。我发现了这些错误

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 190, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/home/sroy8091/college/local/lib/python2.7/site-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 "/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 14, in <module>
    from django.db.migrations.executor import MigrationExecutor
  File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 6, in <module>
    from .loader import MigrationLoader
  File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 10, in <module>
    from django.db.migrations.recorder import MigrationRecorder
  File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 9, in <module>
    class MigrationRecorder(object):
  File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 23, in MigrationRecorder
    class Migration(models.Model):
  File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 24, in Migration
    app = models.CharField(max_length=255)
  File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1081, in __init__
    super(CharField, self).__init__(*args, **kwargs)
  File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 161, in __init__
    self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
  File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
    self._setup(name)
  File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/sroy8091/college/local/lib/python2.7/site-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.

这是我的开发设置

^{pr2}$

我还做了初始化数据库的sql命令,这里的密钥也不为空。尽管它一直在说。我不知道怎么解决这个问题。 这是我的项目目录 enter image description here

我甚至试过设置.py文件,那么这个错误也来了。在


Tags: djangoinpyhomedbinitlibpackages
3条回答

在vanillasettings.py中,您可以通过设置一个环境变量来告诉设置要使用哪个来指定要执行的设置。例如。在

假设您有一个名为DJANGO_env='prod'的env变量,然后在py设置在

import os

environment = os.environ.get('DJANGO_ENV', 'dev')
if environment == 'prod':
     from project_folder.production_settings import *
else:
     from project_folder.development_settings import *

#rest of code

然后尝试:

python manage.py runserver  settings=kgecweb.settings.development

我猜你没用内置的设置.py或者重命名它或者创建一个目录来处理不同的设置.py. 在

编辑

  • 确保你的项目在你的python路径中,用这个来找出答案。在

    import sys
    print(sys.path)
    
  • 或者你可以创建一个py设置然后运行

    python manage.py runserver
    
  • 如果有效,您只需尝试:

    python manage.py runserver  settings=kgecweb.settings.development
    

你把文件名拼错了。在

改变

devlopment.py 

^{pr2}$

一切都应该直接调用文件

相关问题 更多 >