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 ?的更多相关文章

  1. Django基础,Day10 - template 模板引擎与路径设置

    作为一个Web框架,Django需要一个方便的方式来生成动态的HTML.最常见的方法依赖于模板.模板包含所需的HTML输出的静态部分以及一些特殊的语法描述如何插入动态内容. Django框架后端默认支 ...

  2. Django.template框架 template context (非常详细)

    前面的章节我们看到如何在视图中返回HTML,但是HTML是硬编码在Python代码中的 这会导致几个问题: 1,显然,任何页面的改动会牵扯到Python代码的改动 网站的设计改动会比Python代码改 ...

  3. django: template using & debug

    模板的作用方法有如下三种: blog/views.py: from django.template import loader, Context, Template from django.http ...

  4. 63、django之模版层(template)

    上篇主要介绍了django的MTV模型,主要介绍了视图层之路由配置系统url分发和视图层之视图函数view,本篇主要讲解MTV模型中的模版层template. 模版层(template) 一.模版简介 ...

  5. Django——模板层(template)(模板语法、自定义模板过滤器及标签、模板继承)

    前言:当我们想在页面上给客户端返回一个当前时间,一些初学者可能会很自然的想到用占位符,字符串拼接来达到我们想要的效果,但是这样做会有一个问题,HTML被直接硬编码在 Python代码之中. 1 2 3 ...

  6. Django基础三(form和template)

    上一篇博文学习了Django的View和urls,接下来是对django form 和 template的学习. 1 django form django form为我们提供了便捷的方式来创建一些HT ...

  7. Django Template(模板)

    一.模板组成 组成:HTML代码 + 逻辑控制代码 二.逻辑控制代码的组成 1.变量 语法格式 : {{ name }} # 使用双大括号来引用变量 1.Template和Context对象(不推荐使 ...

  8. django之模版层(template)

    上篇主要介绍了django的MTV模型,主要介绍了视图层之路由配置系统url分发和视图层之视图函数view,本篇主要讲解MTV模型中的模版层template. 本篇导论: 模版简介 模版之变量 模版之 ...

  9. django.template.exceptions.TemplateDoesNotExist: login.html 错误处理

    登陆Login界面时候报错 Internal Server Error: /login/ Traceback (most recent call last): File , in inner resp ...

随机推荐

  1. javascript 中break、 continue、函数不能重载

    在javascript中,break与continue有着显著的差别. 如果遇到break语句,会终止最内层循环,无论后面还有多少计算. 如果遇到continue,只会终止此次循环,后面的自循环依然执 ...

  2. php 图片处理类

    <?php /** * 图片类 * @author <420012223@qq.cn> */ class Image { public $uploadImagePath = './t ...

  3. 关于内存数据与 JSON

    闲话: 正在用 WebBroker 写一个小网站,感受颇多: 1.如果是写一个小东西,应该先考虑下 WebBroker,因为它是分分钟即可上手的. 2.如果要写一个大东西,或许也应该考虑下 WebBr ...

  4. DSS中间件介绍

    DSS中间件采用HTTP协议,终端可以是任何的支持Http协议的设备,开发工具和语言均不受限制 DMS消息服务, 采用类似HTTP的协议 DSS-API介绍(持续更新) http://www.dioc ...

  5. Spring 4 官方文档学习(十一)Web MVC 框架之编码式Servlet容器初始化

    在Servlet 3.0+ 环境中,你可以编码式配置Servlet容器,用来代替或者结合 web.xml文件.下面是注册DispatcherServlet : import org.springfra ...

  6. 通过pycurl模块添加put和delete请求

    原文链接: http://anupamshakya.blogspot.com/2013/07/implementation-of-put-and-delete-in.html

  7. python 迭代器和生成器

    1.迭代器协议是指:对象必须提供一个next方法,执行该方法要么返回迭代中的下一项,要么就引起一个StopIteration异常,以终止迭代 (只能往后走不能往前退)2.可迭代对象:实现了迭代器协议的 ...

  8. [Shell]字符截取命令:cut, printf, awk, sed

    ------------------------------------------------------------------------------------------- [cut命令] ...

  9. [Shell]Bash变量:环境变量的配置文件和登录信息

    ----------------------------------------------------------------------------------------- 只有把环境变量放入配 ...

  10. 短信转发Q群

    ※◆☆★☆◆※欢迎使用!!!如有问题或新功能需求请联系作者QQ:82850696*4*您使用的测试版已到期,如需继续使用,请联系作者 QQ : 82850696*0*2015-1-7 23:59:59 ...