"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. Perforce查看workspace sync到的changlist

    一 查看workspace sync到的changelist perforce的workspace其实是一些特定版本的文件的 结合,相比只将workspace对应到某个特定的changelist,此方 ...

  2. 《深入理解Java虚拟机》笔记7

    组内有人问我,她写的程序总是在短时间内就jvm异常. 另外,debug时候又可以正常通过,写的逻辑并不复杂, 只是用poi检索Excel.第一反应还是程序可能写的有问题, 也许写了一个jvm未预测的错 ...

  3. g++动态库静态库混合链接

    今天编译一个程序时报错: g++ -static -o echo.fcgi echo_adaptor.o echo.o -L/usr/local/lib/ -lfastcgipp -L/usr/lib ...

  4. java中compareTo和compare方法之比较,集合中对象的比较

    前言 转自:http://www.cnblogs.com/yueliming/archive/2013/05/22/3092576.html (这里做了一些小改动) 一直一来对集合中对象的比较方案,有 ...

  5. IM开发基础知识补课(四):正确理解HTTP短连接中的Cookie、Session和Token

    本文引用了简书作者“骑小猪看流星”技术文章“Cookie.Session.Token那点事儿”的部分内容,感谢原作者. 1.前言 众所周之,IM是个典型的快速数据流交换系统,当今主流IM系统(尤其移动 ...

  6. js知识梳理2:对象属性的操作

    1.属性的查询和设置 ①基本语法 这个简单,可以通过点(.)或方括号([])运算来获取属性的值,注意点运算符后的标识符不能是保留字,方括号内的表达式必须返回字符串或返回一个可以转换成字符串的值. va ...

  7. recess----2.Controller里面取用request信息

    事实上,第一个APP里面除了没有model,其它的都有用过了,但是需要单独拎出来看看清楚. Recess框架里面的controller就是一个典型的MVC框架的controller,它负责处理从浏览器 ...

  8. 03-hibernate注解-关系映射级别注解-一对一

    实体之间的映射关系 一对一:一个公民对应一个身份证号码 一对多(多对一):一个人可以有多个银行账号 多对多:一个学生有多个老师,一个老师有多个学生. 一对一单向外键关联 @OneToOne(casca ...

  9. 你不知道的js技巧

    JS进阶 说起这个应该算是老生常谈了吧.所谓的高级,其实就是讲了一些我们平常用不到(或许用了不知道),但是非常实在的东西.算是熟练掌握js的一个必经road吧. 检测函数类型 其实检测函数的类型应该算 ...

  10. SCRUM敏捷开发规则一栏

    敏捷.敏捷开发这类词近期非常火!敏捷开发,就是指可以在需求迅速变化的情况下高速开发软件.我们接触最多的和敏捷相关的名词是:极限编程(XP).结对编程.測试驱动开发(TDD)等. 敏捷建模(Agile ...