错误描述:
出现原因:
在命令行下使用python命令进入交互模式的,Template(str)在构照模板的时候依赖django.conf.settings.这个变量,但是在当前的环境中没有这个变量, 这时,它就会抛出异常了
解决方法1:手动须导入settings
解决方法2: 使用python manager.py shell运行
python manager.py shell的时候djano会去查找settings.py,这个文件包含了这个Django实例的所有配置选项
打开这个文件我们可以看到这样的配置
ImportError: Settings cannot be imported, because environment variable
DJANGO_SETTINGS_MODULE is undefined.
出现原因:
在命令行下使用python命令进入交互模式的,Template(str)在构照模板的时候依赖django.conf.settings.这个变量,但是在当前的环境中没有这个变量, 这时,它就会抛出异常了
解决方法1:手动须导入settings
>>> from django.conf import settings
>>> settings.configure()
解决方法2: 使用python manager.py shell运行
C:\Users\Angellin\mysite>python manager.py shell
python manager.py shell的时候djano会去查找settings.py,这个文件包含了这个Django实例的所有配置选项
打开这个文件我们可以看到这样的配置
# List of callables that know how to import
templates from various sources.
TEMPLATE_LOADERS = (
'djan