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 ...
随机推荐
- Spring框架学习(3)spring中使用jdbc
内容源自:spring中使用jdbc spring dao层中对jdbc进行了封装,使用模板模式的设计模式,通过ioc被动注入的方式将jdbcTemplate这个模板类注入到数据对象中,进行数据库操作 ...
- linux中backticks反引号的作用
This is a backtick. A backtick is not a quotation sign. It has a very special meaning. Everything yo ...
- Windows录音API学习笔记
Windows录音API学习笔记 结构体和函数信息 结构体 WAVEINCAPS 该结构描述了一个波形音频输入设备的能力. typedef struct { WORD wMid; 用于波形 ...
- docker学习笔记二:常用命令
docker学习笔记二:常用命令 查看docker常用命令 docker --help 返回结果如下: 其中常用的命令如下: 1.image相关操作 展示所有的image: 删除image: rmi ...
- js中字符串转换为数字
js 字符串转化成数字的三种方法主要有 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数: js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成整数,后 ...
- Android 如何增大开机铃声 M
前言 欢迎大家我分享和推荐好用的代码段~~ 声明 欢迎转载,但请保留文章原始出处: CSDN:http://www.csdn.net ...
- vue - for遍历数组
注释上,也很清楚了哈. 1. item是循环名字,items是循环的数组 <!DOCTYPE html> <html lang="en"> <head ...
- vue - .babelrc
描述:bable-es2015以及babel本身组件在新版本要求的外部配置文件. { "presets": [ ["env", { "modules& ...
- Unity AssetServer小笔记
普及一下Asset Server知识: Unity的Asset Server,其实就是一个纯PostgreSQL数据库.Unity操作Asset Server,就是一个数据库客户端操作,但是Unity ...
- Debian9.3安装NW360无线网卡驱动
最近想把家里的一台老旧台式机利用起来,打算安装Debian9.3,下载ISO,用PowerISO写入到U盘,然后开始安装,过程基本顺利. 就是中间提示缺少“rtl_nic/rtl8105e-1.fw” ...