Why we need template on Django ?

时间:2015-07-07 12:32:11   收藏:0   阅读:109

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:

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!