"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. SqlServer数据库1433端口问题1

    在本地使用telnet ip  1433 命令测试数据库1433端口是否打开,总是提示错误,根据网上查找资料总结了如下两点思路供参考,欢迎指正! (1)第一种情况可能是"Telnet客户端& ...

  2. TensorFlow------单层(全连接层)实现手写数字识别训练及测试实例

    TensorFlow之单层(全连接层)实现手写数字识别训练及测试实例: import tensorflow as tf from tensorflow.examples.tutorials.mnist ...

  3. 转:Android 签名验证机制(相当不错,强烈推荐)

    转:  http://riusksk.blogbus.com/logs/272154406.html Android应用签名验证过程中,满足以下条件才能安装应用: 1.SHA-1(除META-INF目 ...

  4. Linux环境搭建:2. 安装Ubuntu虚拟机

    我家淘宝店,主要协助同学做毕业设计:https://shop104550034.taobao.com/?spm=2013.1.1000126.d21.pPCzDZ 1. 创建虚拟机 1. 打开VMwa ...

  5. jQuery中,实现css格式的改变

    jQuery中,实现属性值的改变 (1)prop属性实现,html中标签的class属性值发生改变: 语法:$(元素标识).prop("class",类属性值); 例子:$(&qu ...

  6. 运行时权限请求框架easypermissions

    前言 之前使用过AndPermission权限申请库,当开发者执行有权限的代码发生异常时,AndPermission会抓到异常并回调到失败中,这里要注意的是会抓到任何异常,不仅仅是没有权限时的异常. ...

  7. OkDownload项目实战

    本文介绍项目中引入okhttp-okgo开源框架里的OkDownload部分,实现了RecyclerView列表的下载功能. 引入OKDownload 需求不仅是要支持断点续传,而且还要支持队列下载和 ...

  8. (原创)开发使用Android studio所遇到的一些问题总结

    1.Android studio下载链接地址(无需FQ):包括先行版和正式版(推荐使用正式版bug少) http://www.androiddevtools.cn/ 2.第一次安装避免成功先不要急着打 ...

  9. Visual studio之C# 调用系统软键盘(外部"osk.exe")

    背景 App需要调用系统软键盘输入数据,自己去实现软键盘有些复杂,现在又是急需,没时间去研究实现软键盘,所以只能调用系统软键盘. 正文 需要添加命名空间, using System.Diagnosti ...

  10. fastdfs安装

    1:安装libevent     rpm -aq |grep libevent|xargs rpm -e --nodeps     tar zxvf libevent-2.0.21-stable.ta ...