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. Nginx配置配置文件nginx.conf的设置

    引用自:http://www.ha97.com/5194.html #定义Nginx运行的用户和用户组user www www; #nginx进程数,建议设置为等于CPU总核心数.worker_pro ...

  2. 用AXIS2发布WebService的方法

    Axis2+tomcat6.0 实现webService 服务端发布与客户端的调用. 第一步:首先要下载开发所需要的jar包 下载:axis2-1.6.1-war.zip http://www.apa ...

  3. 使用Coookie实现浏览器显示上次的登录时间

    实现的效果:  每一次刷新 都会显示上一次访问servlet的时间 ,只适用于同一个浏览器 ,更换浏览器再次访问就该使用session技术了, 因为cookie是浏览器端技术,cookie保存在浏览器 ...

  4. BIEE 11g 安装

    1.安装oracle 创建字符集为AL32UTF8的实力MERIT  sys密码merit 创建biee用户 create tablespace biee datafile 'D:\ORADATA\M ...

  5. grep 相关

    1) -q 参数,本意是 Quiet; do not write anything to standard output.  Exit immediately with zero status if ...

  6. XE3随笔9:使用不同的数据类型标记数组

    unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, For ...

  7. Oracle 游标使用

    今天看到一篇很帮的游标,所以强烈转一下 http://www.cnblogs.com/sc-xx/archive/2011/12/03/2275084.html -- 声明游标:CURSOR curs ...

  8. jquery 获取radio选中的值

    如下案例:常用方法 1.获取选中值,三种方法都可以: $('input:radio:checked').val(): $("input[type='radio']:checked" ...

  9. Okhttp https

    1. 绕过CA证书,不建议使用 private void ingoreCA() throws NoSuchAlgorithmException, KeyManagementException { SS ...

  10. Java入门1dayCode

    public class HelloWorld { /* * 多行注释方式 * main()方法: java语言的入口方法(函数) */ public static void main(String[ ...