gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 10:44:24 34 4
gpt4 key购买 nike

我使用的是 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 但出现同样的错误。

已更新——已设置 secret key 并且也从不缓存 key 。这就是我的 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, ".."))) 更新为我的路径设置.py?

最佳答案

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

或者在你的 manage.py 中修改

settings_module = "%s.settings" % PROJECT_DIRNAME

settings_module = "settings"

它有效地做同样的事情。

关于python - manage.py 在同一文件夹中继续使用 django 的空白 settings.py 而不是 settings.py manage.py 位于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32826266/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com