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

时间:2015-09-28 15:07:41

标签: python django windows python-2.7 filepath

我使用的是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.

但是当我查看settings.py所在的特定文件路径中的settings.py时,它拥有一切。上面的行似乎表明它正在尝试使用django的setting.py而不是已经修复的那个。我也尝试使用python C:/myfilepathtothisspecificfile/manage.py runserver,但发生了同样的错误。

UPDATED - 设置了密钥,也设置了nevercache密钥。这就是我的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)

我应该将行sys.path.insert(0, os.path.abspath(os.path.join(PROJECT_ROOT, "..")))更新为我的settings.py吗?

1 个答案:

答案 0 :(得分:0)

在“控制面板”中将DJANGO_SETTINGS_MODULE变量设置为settings系统|高级系统设置|环境变量

或在您的manage.py更改中

settings_module = "%s.settings" % PROJECT_DIRNAME

settings_module = "settings"

有效地做同样的事情。