django模板报错Requested setting TEMPLATE_DEBUG, but settings are not configured. You must either define

django模板报错Requested
setting TEMPLATE_DEBUG, but settings are not configured. You must either
define

分类:
Django2013-03-16 22:42
2417人阅读 评论(1)
收藏 举报

djangoerror

[plain] view
plain
copy

  1. django模板报错
  2. Requested
    setting TEMPLATE_DEBUG, but settings are not
    configured.

  3. You
    must either define the environment variable
    DJANGO_SETTINGS_MODULE

  4. or
    call settings.configure() before accessing settings.
  5. 直接python命令启动python交互式解释器,导入django
    template会报错
  6. [email protected]:~/djbk$
    pythonPython 2.7.3 (default, Aug 1 2012,
    05:16:07)

  7. [GCC
    4.6.3] on linux2Type "help", "copyright", "credits" or "license" for more
    information.

  8. >>>
    from django import template

  9. >>>
    t = template.Template(‘my name is {{ name }}‘)

  10. Traceback
    (most recent call last): File "<stdin>", line 1, in
    <module>

  11. File
    "/usr/local/lib/python2.7/dist-packages/Django-1.5.dev20120922131713-py2.7.egg/django/template/base.py",

  12. line
    123, in __init__ if settings.TEMPLATE_DEBUG and origin is None: File
    "/usr/local/lib/python2.7/dist-packages/Django-1.5.dev20120922131713-py2.7.egg/django/conf/__init__.py",
    line 50, in __getattr__ self._setup(name) File
    "/usr/local/lib/python2.7/dist-packages/Django-1.5.dev20120922131713-py2.7.egg/django/conf/__init__.py",
    line 43, in _setup % (name,
    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.>>>
  13. 解决方法一:
  14. 先导入settings
  15. >>>
    from django.conf import settings
  16. >>>
    settings.configure()
  17. >>>
    from django import template

  18. >>>
    t = template.Template(‘My name is {{ name }}.‘)

  19. >>>
    c = template.Context({‘name‘: ‘yixiaohan‘})

  20. >>>
    print t.render(c)

  21. My
    name is yixiaohan.

  22. >>>
    c = template.Context({‘name‘: ‘xiaowangge‘})

  23. >>>
    print t.render(c)

  24. My
    name is xiaowangge.
  25. 解决方法二:
  26. 使用python
    manage.py shell启动 Python交互式解释器(实际上启动的是Ipython)
  27. python
    manage.py shell
  28. [email protected]:~/djbk$
    python manage.py shell

  29. Python
    2.7.3 (default, Aug  1 2012, 05:16:07)

  30. Type
    "copyright", "credits" or "license" for more
    information.
  31. IPython
    0.12.1 -- An enhanced Interactive Python.

  32. ?         ->
    Introduction and overview of IPython‘s features.

  33. %quickref
    -> Quick reference.

  34. help      ->
    Python‘s own help system.

  35. object?   ->
    Details about ‘object‘, use ‘object??‘ for extra
    details.
  36. In
    [1]: from django import template
  37. In
    [2]: t = template.Template("my name is {{ name }}")
  38. In
    [3]: c = template.Context({‘name‘:‘yixiaohan‘})
  39. In
    [4]: rt = t.render(c)
  40. In
    [5]: rt

  41. Out[5]:
    u‘my name is yixiaohan‘
  42. In
    [6]: print rt

  43. my
    name is
    yixiaohan


本文由@易枭寒([email protected])整理写成.转载请注明出处和作者信息.

django模板报错Requested setting TEMPLATE_DEBUG, but settings are
not configured. You must either define

时间: 2024-10-20 23:09:49

django模板报错Requested setting TEMPLATE_DEBUG, but settings are not configured. You must either define的相关文章

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

转自: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 a

django中执行py报错Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured

https://blog.csdn.net/heybob/article/details/49684261 django代码下面直接run的时候报错: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJAN

pycharm 中的 Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE 问题解决

昨天遇到一个问题,pycharm 中运行不了django的程序,看错误是: django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before a

python交互式环境,django模板报错:django.core.exceptions.ImproperlyConfigured

环境: ubuntu django 1.5 virtualenv环境中 (web01)[email protected]:~/.virtualenvs/web01/dj_01/pro01$ python Python 2.7.6 (default, Mar 22 2014, 22:59:56)  [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license&q

django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configur

django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. import xadmin时出了这个问

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)

在python的开发中,遇到了这个错误: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before

django交互模式使用模板报:django.core.exceptions.ImproperlyConfigured

(dj_01)[email protected]:~/.virtualenvs/dj_01/mysite$ pwd /home/milo/.virtualenvs/dj_01/mysite (dj_01)[email protected]:~/.virtualenvs/dj_01/mysite$ python >>> from django import template >>> t = template.Template('My name is {{ name }}.

Nginx部署Django项目报错 KeyError: &#39;REQUEST_METHOD&#39;

这个问题是应为Nginx的配置文件有问题: 要使用uwsgi启动Django的话要有以下配置: upstream djangos14{ # nginx负载均衡配置: server 10.0.0.10:9999; #server 10.0.0.11:80; } server { listen 80; server_name www.s14hanju.com; location / { # 要使用uwsgi,代理就不要用proxy_pass了,要使用uwsgi_pass: uwsgi_pass dj

新装python环境启动django程序报错

个人独立博客 http://www.xbman.cn/ 出处:http://www.xbman.cn/article/1 django启动报错 django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3 解决方法 centos yum install python-deve