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 accessing settings."
- 先导入settings
- >>> from django.conf import settings
- >>> settings.configure()
- >>> from django import template
- >>> t = template.Template('My name is {{ name }}.')
- >>> c = template.Context({'name': 'yixiaohan'})
- >>> print t.render(c)
- My name is yixiaohan.
- >>> c = template.Context({'name': 'xiaowangge'})
- >>> print t.render(c)
- My name is xiaowangge.
- 解决方法二:
- 使用python manage.py shell启动 Python交互式解释器(实际上启动的是Ipython)
- python manage.py shell
- yixiaohan@ubuntu:~/djbk$ python manage.py shell
- Python 2.7.3 (default, Aug 1 2012, 05:16:07)
- Type "copyright", "credits" or "license" for more information.
- IPython 0.12.1 -- An enhanced Interactive Python.
- ? -> Introduction and overview of IPython's features.
- %quickref -> Quick reference.
- help -> Python's own help system.
- object? -> Details about 'object', use 'object??' for extra details.
- In [1]: from django import template
- In [2]: t = template.Template("my name is {{ name }}")
- In [3]: c = template.Context({'name':'yixiaohan'})
- In [4]: rt = t.render(c)
- In [5]: rt
- Out[5]: u'my name is yixiaohan'
- In [6]: print rt
- my name is yixiaohan
django 模板报错的更多相关文章
- 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 ...
- django引用模板报错Template file 'index.html' not found
产生报错的原因在于index.html未被引用到,处理办法是在setting.py中加入app的name. 我这里app的名字叫sign,所以加入sign就好了 再次访问就好啦
- 使用T4模板报错:“正在编译转换;当前上下文中不存在名称Host”
用T4模板生成多个文件的实体时,有一句代码是这样的 string curPath = Path.GetDirectoryName(Host.TemplateFile); ...
- 模板函数 使用的默认void 模板报错
You must specify the compiler argument -std=c++0x to avoid the following error: test.cpp:5:13: error ...
- vue 初始化项目模板报错
E:\xiaogezi.cn\vue>vue init webpack myProject vue-cli · Failed to download repo vuejs-templates/w ...
- 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 ...
- django haystack报错: ModuleNotFoundError: No module named 'blog.whoosh_cn_backend'
在配置django haystack时报错: 解决方案: 将ENGINE的值 改为 这样就可以了.
- django运行报错TypeError: object supporting the buffer API required
运行django项目报错:TypeError: object supporting the buffer API required 解决方案: 将settings.py中数据库的密码改成字符串格式 源 ...
- 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 ...
随机推荐
- [Todo] Git & 版本控制学习
下面这篇写的非常好.git分支介绍,有图.好好看这一篇,就懂了: http://www.open-open.com/lib/view/open1328069889514.html 该系列还有不少文章, ...
- LINUX下使用NC反弹CMDSHELL提权
很多时候linux拿到shell了,然后在菜刀或Shell里执行简单命令不允许!说明权限很死或者被管理禁止了!这里我已NC将SHELL反弹回本地提权!先看下linux内核 2.6.18-194.11. ...
- 在Ubuntu Server上源码安装OpenERP 8.0,并配置wsgi和nginx运行环境
原文: How to install OpenERP 8.0 Alpha on a fresh Debian / Ubuntu server. OpenERP的安装,可以有多种方式,通过添加源,到 h ...
- ckeditor 绑定事件
CKEDITOR.instances["Content"].on("instanceReady", function () { //set keyup even ...
- CSS学习(九)-CSS背景
一.理论: 1.background-break a.bounding-box 背景图像在整个内联元素中进行平铺 b.each-box 背景图像在行内中进行平铺 c.continuous 下一行的背 ...
- Cocos2dx&Lua - UI显示优化之怎样解决解析大量json文件
GUIReader中有个widgetFromJsonFile的方法,此方法是用于解析json文件(cocostudio生成的UI的)并返回该文件的父节点(Widget),然后便于进一步的UI操作(如获 ...
- Activity生命周期以及启动模式对生命周期的影响(二)
前面一篇文章概述了Android四大组件之一的Activity生命周期方法的调用先后顺序,但对于非标准启动模式下Activity被多次调用时的一些生命周期方法并未详细阐述,现在针对该情况着重记录. 现 ...
- 类非静态成员的函数指针 的使用 Function pointer of a non-static member function of a class
you can get the pointer of the method, but it has to be called with an object typedef void (T::*Meth ...
- <译>Flink编程指南
Flink 的流数据 API 编程指南 Flink 的流数据处理程序是常规的程序 ,通过再流数据上,实现了各种转换 (比如 过滤, 更新中间状态, 定义窗口, 聚合).流数据可以来之多种数据源 (比如 ...
- HBase ProcedureV2 分析
Procedure V2, 是hbase1.1版本引入的一套fault-tolerant的执行multi-steps-job的框架, 目前主要用在Master中, 比如创建表,删除表等操作 新旧比较 ...