django url 正则表达式收集

django url 正则表达式收集

1
url(r'^about/$',views.about),
url(r'^list/$',views.listing),

只匹配:
localhost:8000/about
localhost:8000/about/
localhost:8000/list
localhost:8000/list/

由于是加上了 $ 符号,所有,不能匹配:
localhost:8000/about/xyz
localhost:8000/about/1

输入localhost:8000/about 的时候,会自动加入 /
变成localhost:8000/about/

2
url(r'^about/[0|1|2|3]/$',views.about),

localhost:8000/about/0
localhost:8000/about/1
localhost:8000/about/2
localhost:8000/about/3

3
url(r'^about/([0|1|2|3])/$',views.about),

def about(request,author_no):
	html = "<h2>Here is Author:{}'s about page!</h2><hr>".format(author_no)
	
	return HttpResponse(html)
4
url(r'^about/(?P<author_no>[0|1|2|3])/$',views.about),

def about(request,author_no):
	html = "<h2>Here is Author:{}'s about page!</h2><hr>".format(author_no)
	
	return HttpResponse(html)
5

localhost:8000/list/2016/05/12

localhost:8000/post/2016/05/12/01

url(r'^list/(?P<list_date>\d{4}/\d{1,2}/\d{1,2})$',views.listing),
url(r'^post/(?P<post_data>\d{4}/\d{1,2}/\d{1,2}/\d{1,3})$', views.post),

def listing(request,list_date):
	html = "<h2>List Date is {} </h2><hr>".format(list_date)
	return HttpResponse(html)
	
def post(request,post_data):
	html = "<h2>Post Data is {} </h2><hr>".format(post_data)
	return HttpResponse(html)


6
url(r'^post/(\d{4})/(\d{1,2})/(\d{1,2})/(\d{1,3})$',views.post),

def post(request,yr,mon,day,post_num):
	html = "<h2>{}/{}/{}:Post Number:{}</h2><hr>".format(yr,mon,day,int(post_num))
	return HttpResponse(html)
7
url(r'^about/$',views.about),
url(r'^about/(?P<author_no>[0|1|2|3])/$',views.abot),

def about(request, author_no = '0'):
	html = "<h2>Here is Author:{}'s about page !</h2><hr>".format(author_no)
	return HttpResponse(html)
8
url(r'^$',views.homepage,{'testmode':'YES'}),

def homepage(request, testmode):
	html = "<h2>Here is mode:{}  homepagepage !</h2><hr>".format(testmode)
	return HttpResponse(html)

在这里插入图片描述

(稍后补充)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值