Django 路由正則URLhtml
URL1ide
# 路由 url(r'^detail/', views.detail) {#點擊跳轉到指定用戶下顯示信息#} <li><a target="_blank" href="/detail/?nid={{ k }}">{{ row.name }}</a></li>
URL2函數
# 返回一個值,d+也能夠寫爲w+任意正則 url(r'^detail-(\d+).html', views.detail) {#點擊跳轉到指定用戶下顯示信息#} <li><a target="_blank" href="/detail-{{ k }}.html">{{ row.name }}</a></li>
URL3ui
# 返回多個值,嚴格按照順序排列 url(r'^detail-(\d+)-(\d+).html', views.detail)
URL4(推薦)url
# 返回多個值並指定變量賦值,不須要按照順序排列 url(r'^detail-(?P<nid>\d+)-(?P<uid>\d+).html', views.detail)
# 路由 url(r'^detail-(\d+)-(\d+).html', views.detail) # 函數可使用*args,能夠自動接收任意個參數 def detail(request,*args): args = (2,9) # 函數可使用*args,**kwargs能夠自動接收任意個參數,**kwargs默認不接收 def detail(request,*args,**kwargs): args = (2,9)
# 路由 url(r'^detail-(?P<nid>\d+)-(?P<uid>\d+).html', views.detail) def detail(request,*args,**kwargs): kwargs = {'nid':1,'uid':3} def detail(request,*args,**kwargs): args = (2,9)
其餘說明spa
提交表單時路由指定url變量3d
# 後面加入第三個參數,參數名稱爲indexx。 path('infdafddsfadsafdsafdsfdasfdsdex/', views.index,name='indexx') # <!-- 引用url返回的路徑變量,直接引用form表單內 --> <form action="{% url 'indexx' %}" method="POST">