django(4):传递参数
from django.http import HttpResponse def hello(request): return HttpResponse('HELLO WORD') def helloParam(request,p1): return HttpResponse('Hello ,%s' %p1) def helloParams(request,p1,p2): return HttpResponse('Hello,p1:%s,p2:%s' %(p1,p2)) def hello1(request,id,name): return HttpResponse('Hello,p1:%s,p2:%s' %(id,name)) def helloPar(request): if len(request.GET.keys())==0: return HttpResponse('HELLO WORD') else: p1=request.GET.get('p1') p2=request.GET.get('p2') return HttpResponse('Hello,p1:%s,p2:%s' %(p1,p2))
urls:
from django.conf.urls import url from django.contrib import admin from app0904 import views urlpatterns=[ url(r'^$',views.main), url(r'^admin/',admin.site.urls), url(r'^hello/$',views.hello), url(r'^hellop1/(.+)/$',views.helloParam), url(r'^hello/(.+)/(.+)/$',views.helloParams), url(r'^hello1/(?P<id>.+)/(?P<name>.+)/$',views.hello1), #限制参数 url(r'^hellopp/',views.helloPar)] ~