Django——模版Template报错
先导入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——模版Template报错的更多相关文章
- django startproject xxx:报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 13: ordinal not in range(128)
django startproject xxx:报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 13: o ...
- Django迁移数据库报错
Django迁移数据库报错 table "xxx" already exists错误 django在migrate时报错django migrate error: table 'x ...
- org.thymeleaf.exceptions.TemplateInputException: Error resolving template 报错
org.thymeleaf.exceptions.TemplateInputException: Error resolving template报错 遇到二次,第一次是刚刚学的时候,都是一个原因,而 ...
- django正常运行确报错的解决方法
django正常运行却报错的处理方法 出处 : https://www.infvie.com/ops-notes/django-normal-operation-error 报错一:self._soc ...
- Django:django-cors-headers 报错no module named "corsheaders"
django跨域使用 pip install django-cors-headers 然后在settings文件中加上参数设置 # app配置 INSTALLED_APPS = [ 'django.c ...
- django调用py报错 django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured.
完整报错信息如下 django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, bu ...
- django 连接mysql报错
原因: 问题1. 即从mysql5.7版本之后,默认采用了caching_sha2_password验证方式. 问题2. 然后在执行 python manage.py makemigrations依 ...
- Django创建App报错
在django下创建APP项目时遇到的坑 python manage.py startapp app01 报错内容如下: 解决:找到报错中的文件夹151行删除items(),)中的逗号即可 在命令行下 ...
- Django 使用allauth报错
一:报错 RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_labe ...
随机推荐
- selenium 3.0 键盘事件 +强制结束chromedriver进程代码
selenium自动化测试常常用到键盘操作,一下是键盘操作的详细操作,和部分代码.截图来自于虫师的自动化相关书籍. public static void main(String[] args) thr ...
- libev 学习使用
libev 简单的I/O库. a high performance full featured event loop written in c libev 的大小也比 libevent 小得多并且自 ...
- hdu 5750(数论)
Dertouzos Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- 内存可见性,指令重排序,JIT。。。。。。从一个知乎问题谈起
在知乎上看到一个问题<java中volatile关键字的疑惑?>,引起了我的兴趣 问题是这样的: package com.cc.test.volatileTest; public clas ...
- Elasticsearch使用java读取数据报错NoNodeAvailableException: None of the configured nodes are available: [127.0.0.1:9300]
对于这个问题,大部分人出现在这个地方: Client client = new TransportClient(settings).addTransportAddress(new InetSocket ...
- 洛谷——P2371 EXCEEDED WARNING C(50)
P2371 EXCEEDED WARNING C 题目背景 第三道溢出警告... 机(wei)智(suo)的TMXi又搬题来坑大家了... 注意时空限制[坏笑] 题目描述 [li]1949年,阿三的数 ...
- ASP.NET Core 2.2 基础知识(十八) 托管和部署 概述
为了方便演示,以 .NET Core 控制台应用程序讲解. 我们新建一个控制台应用程序,安装 "Newtonsoft.Json" Nuget 包,然后右键点击该项目,选择" ...
- hdu 1233 还是畅通工程 最小生成树(prim算法 + kruskal算法)
还是畅通工程 Time Limit: 4000/2 ...
- SQLSERVER LATCH WINDBG
https://mssqlwiki.com/2012/09/07/latch-timeout-and-sql-server-latch/
- zk介绍
1. 配置管理 Zookeeper提供了这样的一种服务:一种集中管理配置的方法,我们在这个集中的地方修改了配置,所有对这个配置感兴趣的都可以获得变更.这样就省去手动拷贝配置了,还保证了可靠和一致性. ...