Why we need template on Django ?
Let's create a simple website by django ...
step01:
django-admin startproject x01
step02:
cd x01
ls
You will see ...

or you can use tree:
tree

step03:
write the first view for your website ...
cd x01
vim views.py
write the below code into your new file ( views.py
from django.http import HttpResponse def hello(request):
return HttpResponse("Hello World")
step04:
Let the django know you have a new view,so add the url to urls.py
vim urls.py
You will see something like below ..

step05
delete all ...
and then write the below code into the ( urls.py )
from django.conf.urls import patterns
from x01.views import hello urlpatterns = patterns('',
('^hello/$,hello),
)
After input ,You will got something like the below ..

step06:
python manage.py runserver
You will see the below ...

step07:
check and see if you can visit ...

If you see this,mean you have success ..
Congratulation ...
step08:
Why we need the template ...?
see the second example,just change your (views.py) like the below ...

and then change the (urls.py ) like below ..

and then visit your website again ..

And ,you must think,it's so boring to write the 'html inline python' ...
so the template is work for you ...
step09:

and change your (urls.py)
like the below show ...

run and check again ..

If you see the result ,you are success again ...
step10:
But we can see,the both python and html still in the same file ( views.py ) ...
We want do samething let it at different file (template.html ) and (views.py) ...
create a templates dir ..
mkdir templates

and then let the django you have new (templates)
cd x01
vim setting.py
You will see:

I have already add the (template ) see line58 ...
and then modify our (views.py )

okay, let's check our website ...

we got a Exception ...
Because,we haven't write our template file name as ( current_datetime.html )
let's do it ..

and check again ...

step11:
Let's see our views.py ,

The line1,2,3 is so boring,Is there any way can change this situation ..
get_template + Context +HttpResponse = ??
The answer is True ...
Modify the views.py like below code ...

and then,check your website ...

If you see the time ...you have success again ...
step12:
Keep let it easy ...
(use locals() instead more temp variable ...)

step13:
Why we need template on Django ?的更多相关文章
- Django基础,Day10 - template 模板引擎与路径设置
作为一个Web框架,Django需要一个方便的方式来生成动态的HTML.最常见的方法依赖于模板.模板包含所需的HTML输出的静态部分以及一些特殊的语法描述如何插入动态内容. Django框架后端默认支 ...
- Django.template框架 template context (非常详细)
前面的章节我们看到如何在视图中返回HTML,但是HTML是硬编码在Python代码中的 这会导致几个问题: 1,显然,任何页面的改动会牵扯到Python代码的改动 网站的设计改动会比Python代码改 ...
- django: template using & debug
模板的作用方法有如下三种: blog/views.py: from django.template import loader, Context, Template from django.http ...
- 63、django之模版层(template)
上篇主要介绍了django的MTV模型,主要介绍了视图层之路由配置系统url分发和视图层之视图函数view,本篇主要讲解MTV模型中的模版层template. 模版层(template) 一.模版简介 ...
- Django——模板层(template)(模板语法、自定义模板过滤器及标签、模板继承)
前言:当我们想在页面上给客户端返回一个当前时间,一些初学者可能会很自然的想到用占位符,字符串拼接来达到我们想要的效果,但是这样做会有一个问题,HTML被直接硬编码在 Python代码之中. 1 2 3 ...
- Django基础三(form和template)
上一篇博文学习了Django的View和urls,接下来是对django form 和 template的学习. 1 django form django form为我们提供了便捷的方式来创建一些HT ...
- Django Template(模板)
一.模板组成 组成:HTML代码 + 逻辑控制代码 二.逻辑控制代码的组成 1.变量 语法格式 : {{ name }} # 使用双大括号来引用变量 1.Template和Context对象(不推荐使 ...
- django之模版层(template)
上篇主要介绍了django的MTV模型,主要介绍了视图层之路由配置系统url分发和视图层之视图函数view,本篇主要讲解MTV模型中的模版层template. 本篇导论: 模版简介 模版之变量 模版之 ...
- django.template.exceptions.TemplateDoesNotExist: login.html 错误处理
登陆Login界面时候报错 Internal Server Error: /login/ Traceback (most recent call last): File , in inner resp ...
随机推荐
- OpenSSL命令---passwd
NAME passwd - compute password hashes SYNOPSIS openssl passwd [-crypt] [-1] [-apr1] [-salt string] [ ...
- 定位一组对象-checkbox 、radiobutton
webdriver 可以很方便的使用find_element 方法来定位某个特定的对象,不过有时候我们却需要定位一组对象,WebElement 接口同样提供了定位一组元素的方法find_element ...
- 记一次 Ubuntu 使用 arptables 抵御局域网 ARP 攻击
. . . . . 前段时间大概有一个月左右,租房的网络每天都断一次,每次断大概一两分钟左右就恢复了,所以没太在意.直到有一天晚上,LZ 正在写博客,但是网络频繁中断又重新连上再中断.待 LZ 好不容 ...
- 图解——VS发布网站详细步骤
1.打开你的VS2012网站项目,右键点击项目>菜单中 重新生成一下网站项目:再次点击右键>发布: 2.弹出网站发布设置面板,点击<新建..>,创建新的发布配置文件: 输入你自 ...
- 利用iframe无刷新上传文件的坑
页面里经常要用到文件上传的功能,而且要求页面不刷新,先说一下原理:页面里放一个file控件和submit按钮,外面用form表单包住,给form表单加上对应的属性值,action.method.ent ...
- 第一个Spring demo
参考Spring3.x企业实战 1.新建web工程chapter5,导入jar包.注意:cglib和commons-dbcp这两个包 2.设计数据库 t_login_log表结构(存放日志信息),主键 ...
- 远程桌面Default.rdp 中各个参数的含义(转)
存储在 Default.rdp 文件中的设置 默认情况下,将在“我的文档”文件夹中创建 Default.rdp 文件.以下 RDP 设置存储在 Desktop.rdp 文件中: desktopwidt ...
- IOS 导航栏
系统状态栏改为白色:在Supporting Files文件的info.plist文件中添加 新的key,名字为View controller-based status bar appearance,并 ...
- 【Java】XML解析之JDOM
JDOM介绍 JDOM是一个开源项目,它基于树型结构,利用纯JAVA的技术对XML文档实现解析.生成.序列化以及多种操作.使用jdom需要引入jdom.jar包. XML生成及解析 代码如下: pac ...
- Redis 集群方案- 主从切换测试
大约一年多前,公司同事开始使用Redis,不清楚是配置,还是版本的问题,当时的Redis经常在使用一段时间后,连接爆满且不释放.印象中,Redis 2.4.8以下的版本由于设计上的主从库同步问题,就会 ...