"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. Ubuntu 13 Zookeeper 集群配置

    一. 目标 在Linux集群搭建Zookeeper集群,并配置管理Web管理系统. 二. 先决条件 本文档中基于VirtualBox Ubuntu Server 13.04 虚机(启动SSH服务器)构 ...

  2. 纯CSS实现多行文字垂直居中几种方法解析

    场景:父元素 高度固定,如何使其中的文字垂直居中? 1.table布局: 利用display:table+display:table-cell的方法 <!DOCTYPE html> < ...

  3. leetcode 282. 给表达式添加运算符

    给定一个仅包含0-9的字符串和一个目标值,返回在数字之间添加了二元运算符(不是一元的) +.-或*之后所有能得到目标值的情况. 例如: "123", 6 -> [" ...

  4. 【笔记】git 的常用操作命令(持续更新。。。)

    项目正在如火如荼的开展,代码量的繁多不得不令我们运用 git 这个有用的工具去管理我们共同协作的代码 git 在这里不作什么介绍了,百度一大堆的教程 首推廖雪峰老师的:http://www.liaox ...

  5. 编译安装mysql-5.6.40

    编译安装mysql-5.6.40 环境说明 系统版本     CentOS 7.2 x86_64 软件版本     mysql-5.6.40 [root@db01 ~]# mkdir -p /serv ...

  6. CentOS7 Failed to start LSB: Bring up/down networking. 已解决!!!

    服务器更换了主板之前配置的静态IP发现启动网卡出现异常. 执行 service network restart 出现以下错误 Restarting network (via systemctl):  ...

  7. 开机自启动:从busybox到debian

    需要在mint上设置opensips的开机自启动,翻了半天资料还是一知半解.最后在opensips的官方文档,查到用下面的语句,添加自启动成功.不过貌似还是会有启动不成功,没有仔细测试过. updat ...

  8. windows磁盘API实践

    API的列表如下,网上找的,我觉得还是蛮详细的: 磁盘和驱动器管理APIGetLogicalDrivers       获取主机中所有的逻辑驱动器,以BitMap的形式返回.GetLogicalDri ...

  9. javascript Date日期类

      四.Date日期类 迁移时间:2017年5月27日18:43:02 Author:Marydon (一)对日期进行格式化(日期转字符串) 自定义Date日期类的format()格式化方法 方式一: ...

  10. 07-spring学习-bean的其他配置(了解)

    首先需要明确,默认情况下,只要在applicationContext.xml文件里面配置的时候自动进行构造方法初始化. 但是用户也可以实现自己的配置,让其在第一次使用的时候进行初始化,这种操作叫做 延 ...