简体   繁体   English

manage.py继续使用Django的空白settings.py而不是同一文件夹中的settings.py。

[英]manage.py keeps using django's blank settings.py instead of settings.py in the same folder manage.py is in

I am using Windows 8.1 and Python 2.7 and I have all the files set up (hopefully correctly) in a specific file path but whenever I run python manage.py runserver I keep getting this error. 我正在使用Windows 8.1和Python 2.7,并且已在特定文件路径中设置了所有文件(希望正确),但是每当我运行python manage.py runserver我都会不断收到此错误。

PS C:\Users\AWelborn\.virtualenvs\truthabouttrees\truth-about-trees> python manage.py runserver
C:\Python27\lib\site-packages\mezzanine\utils\conf.py:59: UserWarning: TIME_ZONE setting is not set, using closest match
: America/Denver
  warn("TIME_ZONE setting is not set, using closest match: %s" % tz)
C:\Python27\lib\site-packages\mezzanine\utils\conf.py:92: UserWarning: mezzanine.pages.context_processors.page is requir
ed in the TEMPLATE_CONTEXT_PROCESSORS setting. Adding it now, but you should update settings.py to explicitly include it
.
  "explicitly include it." % cp)
Traceback (most recent call last):
  File "manage.py", line 29, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 279, in execute
    saved_locale = translation.get_language()
  File "C:\Python27\lib\site-packages\django\utils\translation\__init__.py", line 154, in get_language
    return _trans.get_language()
  File "C:\Python27\lib\site-packages\django\utils\translation\__init__.py", line 52, in __getattr__
    if settings.USE_I18N:
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 54, in __getattr__
    self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 49, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 151, in __init__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

But when I look into the settings.py in the specific file path where settings.py is, it has everything. 但是,当我查看settings.py所在的特定文件路径中的settings.py时,它具有所有功能。 The lines above seem to indicate that it is trying to use django's setting.py instead of the one that already was fixed up. 上面的几行似乎表明它正在尝试使用django的setting.py而不是已经修复的那个。 I also tried to use python C:/myfilepathtothisspecificfile/manage.py runserver but the same error occurs. 我也尝试使用python C:/myfilepathtothisspecificfile/manage.py runserver但发生相同的错误。

UPDATED -- secret keys is set and nevercache key as well. 更新-设置了秘密密钥,也设置了Nevercache密钥。 This is what my manage.py looks like atm. 这就是我的manage.py看起来像atm。

from __future__ import absolute_import, unicode_literals

import os
import sys


# Corrects some pathing issues in various contexts, such as cron jobs,
# and the project layout still being in Django 1.3 format.
from settings import PROJECT_ROOT, PROJECT_DIRNAME
os.chdir(PROJECT_ROOT)
sys.path.insert(0, os.path.abspath(os.path.join(PROJECT_ROOT, "..")))


# Add the site ID CLI arg to the environment, which allows for the site
# used in any site related queries to be manually set for management
# commands.
for i, arg in enumerate(sys.argv):
    if arg.startswith("--site"):
        os.environ["MEZZANINE_SITE_ID"] = arg.split("=")[1]
        sys.argv.pop(i)


# Run Django.
if __name__ == "__main__":
    settings_module = "%s.settings" % PROJECT_DIRNAME
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)
    from django.core.management import execute_from_command_line
    execute_from_command_line(sys.argv)

Am I supposed to update the line sys.path.insert(0, os.path.abspath(os.path.join(PROJECT_ROOT, ".."))) to my path to settings.py? 我是否应该将sys.path.insert(0, os.path.abspath(os.path.join(PROJECT_ROOT, "..")))为我的settings.py路径?

Setup DJANGO_SETTINGS_MODULE variable to settings in Control Panel | DJANGO_SETTINGS_MODULE变量settings为“控制面板”中的settings System | 系统| Advanced System Settings | 高级系统设置| Environment Variables 环境变量

Or in your manage.py change 或在您的manage.py更改中

settings_module = "%s.settings" % PROJECT_DIRNAME

to

settings_module = "settings"

which does efficiently the same thing. 有效地做同样的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM