django url 사용 총화

1      
  URL      :
(r'^hello/$', hello)
 def hello(request):
    return HttpResponse("Hello World")
  http://127.0.0.1:8000/hello,     “Hello World”

2       
  URL      ,URL           :
(r'^plist/(.+)/$', helloParam)
 def helloParam(request,param1):
    return HttpResponse("The param is : " + param1)
  http://127.0.0.1:8000/plist/china,     ”The param is : china”

3       
       ,         ,  URL      ,URL           :
(r'^plist/p1(\w+)p2(.+)/$', helloParams)
 def helloParams(request,param1,param2):
    return HttpResponse("p1 = " + param1 + "; p2 = " + param2)
  http://127.0.0.1:8000/plist/p1chinap22012/
   ”p1 = china; p2 = 2012″

       ,        URL    ,           。                 ,       ,URL      ,         ,         。

4      ”?”    
  ,http://127.0.0.1:8000/plist/?p1=china&p2=2012,url ‘?’         ,     p1 p2    。
           ,                    。 Django ,          request.GET.get     。
  URL      :
(r'^plist/$', helloParams1)
 def helloParams(request):
    p1 = request.GET.get('p1')
    p2 = request.GET.get('p2')
    return HttpResponse("p1 = " + p1 + "; p2 = " + p2)
     ”p1 = china; p2 = 2012″

좋은 웹페이지 즐겨찾기