配URl及其视图如下
url(r^'hello',views.hello)
def hello(request):
return HttpResponse('hello word!')
配置URL及其视图如下,url中通过正则指定一个参数
url(r^'hello/(.+)/$',views.hello)
def hello(request,paraml):
return HttpResponse('the param is' + paraml)
#访问http://127.0.0.1:8000/hello/china,输出结果为”The param is : china”
以传递两个参数为例,配置URL及其视图如下,URL中通过正则指定两个参数
url(r'^hello/p1(\w+)p2(.+)/$', views.hello)
def hello(request,param1,param2):
return HttpResponse(p1 = param1,p2=param2)
#访问http://127.0.0.1:8000/hello/p1chinap22012/ 输出为”p1 = china; p2 = 2012″
配置URL及其视图如下
def helloParams(request):
p1 = request.GET.get('p1')
p2 = request.GET.get('p2')
return HttpResponse("p1 = " + p1 + "; p2 = " + p2)