我尝试在eclipse上使用模板库Django。到目前为止,我下载了Django-1.7.tar.gz并解压缩了它。然后,在eclipse中,我将其作为外部库放置,这样我就可以导入模块。我可以导入模块,不使用它,编译我的代码就没有问题了。但是,当我调用template()时,我遇到了问题。
代码:
import numpy as np
from django.template import Template, Context
t=Template("My name is {{my_name}}.")
c=Context({"my_name":"Adrian"})
t.render(c)输出错误
Traceback (most recent call last):
File "C:\Users\212412120\workspace\protype_1\main.py", line 8, in <module>
t=Template("My name is {{my_name}}.")
File "C:\Users\212412120\Downloads\Django-1.7\Django- 1.7\django\template\base.py", line 130, in __init__
if settings.TEMPLATE_DEBUG and origin is None:
File "C:\Users\212412120\Downloads\Django-1.7\Django- 1.7\django\conf\__init__.py", line 46, in __getattr__
self._setup(name)
File "C:\Users\212412120\Downloads\Django-1.7\Django-1.7\django\conf\__init__.py", line 40, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting TEMPLATE_DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.我认为这与环境变量有关,但我不确定。对如何解决这个问题有什么想法吗?
发布于 2015-10-22 00:47:43
我得到了答案,你必须调用settings.configure(),它看起来像这样。
import django.conf import settings
settings.configure() https://stackoverflow.com/questions/33261628
复制相似问题