Djangoのプロジェクト以外でDjangoを使う

Djangoのプロジェクト以外でDjangoを使う方法。settings.configure()を実行しておけばsettings回りのエラーは出ない。
テンプレートエンジンだけを使ってみる場合はこんな感じ。

sample_template.py

from django.conf import settings
settings.configure()
from django.template import Template, Context

def main():
    t = Template('{% for hoge in fuga %}{{ hoge|urlize }} {% endfor %}')
    c = Context({'fuga': [1,'abc','http://www.google.com/']})
    print t.render(c)

if __name__ == '__main__':
    main()

実行結果

1 abc <a href="http://www.google.com/" rel="nofollow">http://www.google.com/</a>