Django正则表达式URL

url(r'^detail-(?P\d+)-(?P\d+).html/', views.detail)


指定两个形参可以利用以下方式接收

def detail(request, nid, uid):
    print(nid, uid)

常用路由写法:

1、
url(r'^detail-(\d+)-(\d+).html/', views.detail)
def func(request, nid, uid):
pass

def func(request, *args):
args = (2,9)

2、
url(r'^detail-(?P\d+)-(?P\d+).html/', views.detail)
def func(request, nid, uid):
pass
def func(requset, **kwargs):
kwargs = {‘nid’ : 1, ‘uid’ : 3}
def func(request, *args):
args = (2,9)

url的使用

1、
url(r'^index/', views.index, name="indexx"),
使用:
2、 url(r'^index/(\d+)/', views.index, name="indexx"), 使用:

你可能感兴趣的:(python-django)