【发布时间】:2015-09-28 15:07:40
【问题描述】:
我使用的是 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,但出现同样的错误。
已更新 -- 设置了密钥,并且也设置了 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 路径?
【问题讨论】:
-
您是否检查了错误消息告诉您的内容:django.core.exceptions.ImproperlyConfigured:SECRET_KEY 设置不能为空。?您的 settings.py 中有 SECRECT_KEY 设置吗?如果没有,请添加它。 docs.djangoproject.com/en/1.8/ref/settings/#secret-key
-
如果您通过 startproject 命令实例化项目,您应该会发现设置模块可以在包含 startproject 'name' 参数的目录中找到。如果您更改了结构或手动创建了项目,请查看您的 manage.py 文件,并发现它有一个指向您的设置预期位置的虚线路径
-
@HeddevanderHeide 你的意思是在 manage.py from settings import PROJECT_ROOT, PROJECT_DIRNAME os.chdir(PROJECT_ROOT) sys.path.insert(0, os.path.abspath(os.path.join(PROJECT_ROOT) , "..") 我需要把“..”改成设置所在的路径吗?
-
不,我建议你尝试设置 DJANGO_SETTINGS_MODULE 或更改 manage.py 中的 settings_module
标签: python django windows python-2.7 filepath