django模板報錯:Requested setting TEMPLATE_DEBUG, but settings are not configured. You must either define

qinfengxiaoyue發表於2014-07-14

轉自:http://blog.csdn.net/xiaowanggedege/article/details/8651236

    django模板報錯:

    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.

     

    好的解決辦法:

    先匯入settings

    >>> from django.conf import settings

    >>> settings.configure()

    >>> from django import template
    >>> t = template.Template('My name is {{ name }}.')
    >>> c = template.Context({'name': 'yixiaohan'})
    >>> print t.render(c)
    My name is yixiaohan.
    >>> c = template.Context({'name': 'xiaowangge'})
    >>> print t.render(c)
    My name is xiaowangge.

相關文章