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 ...
随机推荐
- MySQL5.6安装步骤(windows7/8_64位)
[转]MySQL5.6安装步骤(windows7/8_64位) 1. 下载MySQL Community Server 5.6.11 2. 解压MySQL压缩包 将以下载的MySQL压缩包解压到自定义 ...
- Python程序员技能表—446家知名企业的Py招聘信息(转载)
Python程序员技能表—446家知名企业的Py招聘信息 转载: python 正在学习python或者想学习python的可以加群:330637182 正在学习python或者想学习python的可 ...
- [ES6] 09. Destructuring Assignment -- 2
Read More: http://es6.ruanyifeng.com/#docs/destructuring Array “模式匹配”,只要等号两边的模式相同,左边的变量就会被赋予对应的值: Ex ...
- jQuery选取表单元素
表单元素选择器 选择器 说明 :button <button>元素和type属性值为button的<input& ...
- 自开发实现Quartz Web管理
网上能找到的QuartzWeb管理的资料都是使用的一个国外人写的Quartz WebApp的东东.功能也非常全面. 可是作为自己的应用其有用不了那么多功能,一般我们仅仅要能够定义一个job,指定一个C ...
- ModelAndView command
new ModelAndView("student", "command", new Student()); 对“如果在JSP中使用<form:form& ...
- cordova百度地图定位Android版插件
本插件利用百度地图提供的定位功能进行Android版手机定位. 为什么没有iOS版? 因为iOS版有官方的定位插件cordova-plugin-geolocation可以使用. 请参照:cordova ...
- StarUML 破解方法
在安装目录的:StarUML\www\license\node 找到LicenseManagerDomain.js 在 try 前面加上: return { name:"0xcb" ...
- Python-装饰器进阶
基本概念 具体概念请先看之前的文章 理解装饰器 装饰器是一个很著名的设计模式,经常被用于有切面需求的场景,较为经典的有插入日志.性能测试.事务处理, Web权限校验, Cache等. 很有名的例子,就 ...
- JavaScript-CasperJs使用教程
如果是类似12306这种网站的话, 必须使用--ssl-protocol=any --ignore-ssl-errors=true选项, 例如 casperjs --ssl-protocol=any ...