命令行调试Django的Template功能时碰到的问题及解决方案

背景:正常安装python和Django,python命令行执行如下命令报错

C:\Users\Heyn>python
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from django.template import Template, Context
>>> t = Template('Hello, {{ name }}')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\django\template\base.py", line 182, in __i
nit__
    engine = Engine.get_default()
  File "C:\Python27\lib\site-packages\django\utils\lru_cache.py", line 124, in w
rapper
    result = user_function(*args, **kwds)
  File "C:\Python27\lib\site-packages\django\template\engine.py", line 88, in ge
t_default
    django_engines = [engine for engine in engines.all()
  File "C:\Python27\lib\site-packages\django\template\utils.py", line 110, in al
l
    return [self[alias] for alias in self]
  File "C:\Python27\lib\site-packages\django\template\utils.py", line 107, in __
iter__
    return iter(self.templates)
  File "C:\Python27\lib\site-packages\django\utils\functional.py", line 33, in _
_get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Python27\lib\site-packages\django\template\utils.py", line 31, in tem
plates
    self._templates = settings.TEMPLATES
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 55, in __ge
tattr__
    self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 41, in _set
up
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting TEMPLATES, but se
ttings are not configured. You must either define the environment variable DJANG
O_SETTINGS_MODULE or call settings.configure() before accessing settings.
>>>

解决方案:

>>> from django.conf import settings
>>> settings.configure()

>>> import django
>>> django.setup()



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值