"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."

  1. 先导入settings
  2. >>> from django.conf import settings
  3. >>> settings.configure()
  4. >>> from django import template
  5. >>> t = template.Template('My name is {{ name }}.')
  6. >>> c = template.Context({'name': 'yixiaohan'})
  7. >>> print t.render(c)
  8. My name is yixiaohan.
  9. >>> c = template.Context({'name': 'xiaowangge'})
  10. >>> print t.render(c)
  11. My name is xiaowangge.
  12. 解决方法二:
  13. 使用python manage.py shell启动 Python交互式解释器(实际上启动的是Ipython)
  14. python manage.py shell
  15. yixiaohan@ubuntu:~/djbk$ python manage.py shell
  16. Python 2.7.3 (default, Aug  1 2012, 05:16:07)
  17. Type "copyright", "credits" or "license" for more information.
  18. IPython 0.12.1 -- An enhanced Interactive Python.
  19. ?         -> Introduction and overview of IPython's features.
  20. %quickref -> Quick reference.
  21. help      -> Python's own help system.
  22. object?   -> Details about 'object', use 'object??' for extra details.
  23. In [1]: from django import template
  24. In [2]: t = template.Template("my name is {{ name }}")
  25. In [3]: c = template.Context({'name':'yixiaohan'})
  26. In [4]: rt = t.render(c)
  27. In [5]: rt
  28. Out[5]: u'my name is yixiaohan'
  29. In [6]: print rt
  30. my name is yixiaohan

django 模板报错的更多相关文章

  1. 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 TEMPLAT ...

  2. django引用模板报错Template file 'index.html' not found

    产生报错的原因在于index.html未被引用到,处理办法是在setting.py中加入app的name. 我这里app的名字叫sign,所以加入sign就好了 再次访问就好啦

  3. 使用T4模板报错:“正在编译转换;当前上下文中不存在名称Host”

             用T4模板生成多个文件的实体时,有一句代码是这样的 string curPath = Path.GetDirectoryName(Host.TemplateFile);       ...

  4. 模板函数 使用的默认void 模板报错

    You must specify the compiler argument -std=c++0x to avoid the following error: test.cpp:5:13: error ...

  5. vue 初始化项目模板报错

    E:\xiaogezi.cn\vue>vue init webpack myProject vue-cli · Failed to download repo vuejs-templates/w ...

  6. python---补充django中文报错(1),Django2.7使用sys.setdefaultencoding('utf-8'),以及使用reload(sys)原因

    SyntaxError at /blog/ news/story Non-ASCII character , but no encoding declared; see http://python.o ...

  7. django haystack报错: ModuleNotFoundError: No module named 'blog.whoosh_cn_backend'

    在配置django haystack时报错: 解决方案: 将ENGINE的值 改为 这样就可以了.

  8. django运行报错TypeError: object supporting the buffer API required

    运行django项目报错:TypeError: object supporting the buffer API required 解决方案: 将settings.py中数据库的密码改成字符串格式 源 ...

  9. django migrate报错:1005 - Can't create table xxx (errno: 150 "Foreign key constraint is incorrectly formed")

    自从mysql升级,以及使用mariaDB以来,很多不曾更新django中model的外键, 今天,按以前的思路写完外键之后, migrate命令报错: 1005 - Can't create tab ...

随机推荐

  1. MFC【17-1】线程和线程同步化

    17.1线程 对于Windows来说所有的线程都是一样的,但MFC却把线程区分为两种类型:User Interface(UI) threads(用户界面(UI)线程)和Worker threads(工 ...

  2. 关于C#中async/await中的异常处理(上)

    关于C#中async/await中的异常处理(上) 2012-04-11 09:15 by 老赵, 17919 visits 在同步编程中,一旦出现错误就会抛出异常,我们可以使用try…catch来捕 ...

  3. Java笔记11:JSP连接Oracle数据库

    1 建立Web项目 在D:\tomcat\webapps\中建立basicSyntax项目,在该项目中添加WEB-INF,WEB-INF\classes\,WEB-INF\lib\和WEB-INF\w ...

  4. 【Linux】Ubuntu vi 上下左右变ABCD及 apt-get install报错问题解决方法

    新装的ubuntu12.04,本人绝对新手,在使用VI编辑器编辑文本时觉得实在是难用,因此找了几个解决方法如下: 1. 安装vim full版本 由于Ubuntu预安装的是tiny版本,就会导致我们在 ...

  5. php中自定义事件---事件驱动

    PHP中自定义事件驱动,处理机制. 原文:https://www.cnblogs.com/mafeifan/p/4322271.html ------------------------------- ...

  6. ExportAsFixedFormat Visio文件另存为其他几种格式的处理

    Visio文件另存为其他几种格式的处理,以及另存为Web文件等相关操作. 1.Visio导出为PDF格式 在一般情况下,PDF格式是较为常用的内容格式,因此Visio文档(Vsd格式)导出为PDF也是 ...

  7. PHP5.3下加速器ZendGuardLoader安装 (LNMP/lnmpa)

    PHP5.3下加速器ZendGuardLoader安装 (LNMP/lnmpa) 由于Zend新产品ZendGuardLoader的面世,Zend Optimizer已经不支持php5.3了,官方给出 ...

  8. 云计算之路-阿里云上:SLB故障引发的网站不能正常访问

    2013年8月22日23:50~23:58左右,由于阿里云SLB(负载均衡)故障造成网站不能正常访问,给大家带来了麻烦,望大家谅解! 8月19日我们收到阿里云的短信通知: 尊敬的阿里云用户:      ...

  9. 创建CSS3警示框渐变动画

    来源:GBin1.com 在线演示   在线下载 现代的网页设计技术已经允许开发人员在大多数浏览器中快速实现所支持的动画,其中消息警示是非常普遍的.由于默认的JavaScript警示框往往设计不佳和过 ...

  10. C# Conditional特性避免 预处理命令泛滥使用

    //#define CONDITION1 #define CONDITION2 using System; using System.Diagnostics; class Test { static ...