django之创建第7-5-第二种传值方式(time/1232/xiaodneg)

1、修改views文件

def foo(request,myID,myName):
    t = loader.get_template("foo.html")
    user = {"today": datetime.datetime.now(),"id":myID,"name":myName}
    c = Context(user)
    return HttpResponse(t.render(c))

2、创建foo.html文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>time</title>
</head>
<body>
<li>1、当前时间:{{today}}</li><br>
<li>my id:{{id}}</li>
<li>my name:{{name}}</li>
</body>
</html>

3、配置C:\djangoweb\helloworld\blog\urls文件

# -*- coding: UTF-8 -*-
from django.conf.urls import patterns, include, url


urlpatterns = patterns('blog.views',
url(r'^index/$', 'index'),
url(r'^time/$', 'time'),
url(r'^shengfen/$', 'shengfen'),
#url(r'^foo/(\d{4})/$', 'foo'), #表示接收4个数字
url(r'^foo/(\d{4})/(\w+)/$',"foo")#\w+接收至少一个字母
)

 

4、运行:http://127.0.0.1:8000/blog/foo/1111/xiaodeng/

5、百度云盘:django之创建第7-5-第二种传值方式(time/1232/xiaodneg)

posted @ 2016-04-05 02:31  Xiao|Deng  阅读(151)  评论(0编辑  收藏  举报