python Django 路由之正则表达式
一、路由系统,URL
1. url(r'^index',views.index) #默认的 url(r'^home',views.Home.as_view()) # CBV 形式 也就是说 class
2.url(r'^detail-(\d+).html', views.detail), # 在views里 def home(request, nid, uid) 这两个参数不能调换循序 #http://www.baidu.com/detail-2-8.html 2是nid 8是uid
3.url(r'^detail-(?P<nid>\d+)-(?P<uid>\d+).html', views.detail) #多个正则 在views里 def home(request, nid, uid) 这两个参数可以没有顺序
PS :
url(r'^detail-(\d+).html', views.detail),
def detail(request, *args, **kwargs) 这种方式可以替换 def detail(request,nid,uid)
实战:
a.
url(r'^detail-(\d+)-(\d+).html', views.detail),
def func(request, nid, uid):
def func(reuqest, *args):
def func(request, *args, **kwargs)
b.
url(r'^detail-(?P<nid>\d+)-(?P<uid>\d+).html', views.detail)
def func(request, nid, uid):
def func(request, **kwargs): #或者 *args **kwargs 这样的话就有一个没有值的
kwargs= {'nid':1, 'uid':3}
最新文章
- Kafka Linux 安装
- 教你轻松计算AOE网关键路径(转)
- VC++中StretchBlt图像失真问题的解决办法
- asp.net程序员初涉node.js
- 一、Docker之旅
- PRISM ‘VS100COMNTOOLS’ not set. Cannot set the build environment
- Linux基本配置
- 自定义绘制View
- 检测鼠标键盘多久没有活动(使用GetLastInputInfo API函数检测)
- MVC Controller 与 View 传值
- Nginx中location配置[转]
- HTTP 响应
- MYSQL高可用(HA)随想
- docke镜像上传到dockerhub仓库和阿里云docker仓库的方法
- 【Android 应用开发】Android UI 设计之 TextView EditText 组件属性方法最详细解析
- ElasticSeaarch 遇到的问题 (-)
- python学习笔记(三)- 字典、集合
- HDU 4348 To the moon(主席树区间修改)
- 【题解】【THUSC 2016】成绩单 LOJ 2292 区间dp
- 远程桌面能连接到服务器,但PING不通