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. 如何查看linux内核的版本号?

    zz:http://www.cnblogs.com/hnrainll/archive/2011/06/08/2074957.html 方法一: 命令: uname -a 作用: 查看系统内核版本号及系 ...

  2. mysql学习(二)

    (1)存储过程:存储过程是SQL语句和控制语句的预编译集合,以一个名称存储并作为一个单元处理: (2)存储过程优点:增强SQL语句的功能和灵活性,实现较快的执行速度,减少网络流量: (3)存储过程结构 ...

  3. POJ 2186-Popular Cows (图论-强联通分量Korasaju算法)

    题目链接:http://poj.org/problem?id=2186 题目大意:有n头牛和m对关系, 每一对关系有两个数(a, b)代表a牛认为b牛是“受欢迎”的,且这种关系具有传递性, 如果a牛认 ...

  4. linux开机启动

    开机过程指的是从打开计算机电源直到LINUX显示用户登录画面的全过程.分析LINUX开机过程也是深入了解LINUX核心工作原理的一个很好的途径. 启动第一步--加载BIOS 当你打开计算机电源,计算机 ...

  5. andorid service 本地服务

    ActivityManifect.xml <?xml version="1.0" encoding="utf-8"?> <manifest x ...

  6. android里R.layout.的问题

    今天,在Exlipse里的一个项目在.java文件里写  setContentView(R.layout.activity_problem);时,显示错误,以为是R.java文件里没有对应的activ ...

  7. com.apache.dc.query.Query所属包名apache-common-sid.jar

    com.apache.dc.query.Query所属包名apache-common-sid.jar 首先这个类是基于HQL的,好多方法里面要传String clzz, 刚开始我真不知道这个参数传什么 ...

  8. Adding AirDrop File Sharing Feature to Your iOS Apps

    http://www.appcoda.com/ios7-airdrop-programming-tutorial/ Adding AirDrop File Sharing Feature to You ...

  9. struts的DevMode模式

    在实际应用开发或者是产品部署的时候,对应着两种模式:开发模式(devMode):此时 DevMode=ture: 产品模式(proMode):此时  DevMode=false: 在一些服务器或者框架 ...

  10. centos(Linux)系统阿里云ECS搭建 jdk,tomcat和MySQL环境,并部署web程序

    之前我对这个东西一无所知,攻击力为0,谢谢各个论坛上面的兄弟们的帮助. 过程: 首先ssh远程登陆: ssh root@你的公网ip ,输入密码 1,jdk我用的版本是jdk-7u80-linux-x ...