首页 > 其他 > 详细

Why we need template on Django ?

时间:2015-07-07 12:32:02      阅读:232      评论:0      收藏:0      [点我收藏+]

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:

 

Why we need template on Django ?

原文:http://www.cnblogs.com/landpack/p/4626425.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!