Django Bookをやってる
The Django Book
Chapter4でテンプレートエンジンと戯れて勉強するところがあるんだけd
普通にipythonでやろうとしたら上手く動かなかった
$ ipython Python 2.7.3 (default, Sep 26 2012, 21:53:58) Type "copyright", "credits" or "license" for more information. In [1]: from django import template In [2]: t = template.Template('My name is {{ name }}.') --------------------------------------------------------------------------- ImproperlyConfigured Traceback (most recent call last) <ipython-input-2-9c841ae308d6> in <module>() (中略) 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.
ググったら中国の人のブログに解決法が載ってた
django模板报错Requested setting TEMPLATE_DEBUG, but settings are not configured. You must either define - xiaowanggedege的专栏 - 博客频道 - CSDN.NET
ので、以下のようにipython -iでmanage.pyを読み込んだら動いた
$ ipython -i manage.py Python 2.7.3 (default, Sep 26 2012, 21:53:58) In [1]: from django import template In [2]: t = template.Template('My name is {{ name }}.') In [3]: c = template.Context({'name': 'Fred'}) In [4]: print t.render(c) My name is Fred.
めでたし