019:re_path函数详解

re_path使用:

1、re_path和path的作用是一样的,只不过re_path在写url的时候可以使用正则表达式——功能更加强大;

2、使用正则表达式时,推荐使用原生字符串(即:已 r 开头的字符串);

3、在正则表达式中定义变量,需要使用小括号括起来(例如匹配年份的表达式:(?P<year>\d{4})或 (?P<year>[0-9]{4}));下图是个实例:

 

4、如非特殊需求(要求),直接使用path就够用了,省得将代码搞得很麻烦(说不定,相对比较复杂的表达式——过几天自己都认不得自己为什么这样写);除非url中需要使用正则来匹配才使用:re_path ;

转载于:https://www.cnblogs.com/zheng-weimin/p/10160498.html

urlpatterns = [ path('xadmin/', admin.site.urls), path(r'index/',views.index), path('{}/'.format(schemaName),include('main.urls')),#导入schemaName re_path(r'admin/lib/(?P<p1>.*)/(?P<p2>.*)$', views.admin_lib2), re_path(r'admin/lib/(?P<p1>.*)/(?P<p2>.*)/(?P<p3>.*)$', views.admin_lib3), re_path(r'admin/lib/(?P<p1>.*)/(?P<p2>.*)/(?P<p3>.*)/(?P<p4>.*)$', views.admin_lib4), re_path(r'admin/page/(?P<p1>.*)$', views.admin_page), re_path(r'admin/page/(?P<p1>.*)/(?P<p2>.*)$', views.admin_page2), re_path(r'admin/pages/(?P<p1>.*)$', views.admin_pages), re_path(r'admin/pages/(?P<p1>.*)/(?P<p2>.*)$', views.admin_pages2), re_path(r'front/(?P<p1>.*)$', views.schema_front1), re_path(r'front/(?P<p1>.*)/(?P<p2>.*)$', views.schema_front2), re_path(r'front/(?P<p1>.*)/(?P<p2>.*)/(?P<p3>.*)$', views.schema_front3), re_path(r'front/(?P<p1>.*)/(?P<p2>.*)/(?P<p3>.*)/(?P<p4>.*)$', views.schema_front4), re_path(r'{}/front/(?P<p1>.*)$'.format(schemaName), views.schema_front1), re_path(r'{}/front/(?P<p1>.*)/(?P<p2>.*)$'.format(schemaName), views.schema_front2), re_path(r'{}/front/(?P<p1>.*)/(?P<p2>.*)/(?P<p3>.*)$'.format(schemaName), views.schema_front3), re_path(r'{}/front/(?P<p1>.*)/(?P<p2>.*)/(?P<p3>.*)/(?P<p4>.*)$'.format(schemaName), views.schema_front4), # re_path(r'assets/(?P<p1>.*)$', views.assets1), # re_path(r'assets/(?P<p1>.*)/(?P<p2>.*)$', views.assets2), # re_path(r'assets/(?P<p1>.*)/(?P<p2>.*)/(?P<p3>.*)$', views.assets3), # re_path(r'assets/(?P<p1>.*)/(?P<p2>.*)/(?P<p3>.*)/(?P<p4>.*)$', views.assets4), #re_path(r'admin/(?P<p1>.*)$', views.admin_file1), re_path(r'admin/(?P<p1>.*)/(?P<p2>.*)$', views.admin_file2), re_path(r'admin/(?P<p1>.*)/(?P<p2>.*)/(?P<p3>.*)$', views.admin_file3), re_path(r'admin/(?P<p1>.*)/(?P<p2>.*)/(?P<p3>.*)/(?P<p4>.*)$', views.admin_file4), re_path(r'layui/(?P<p1>.*)$', views.layui1), re_path(r'layui/(?P<p1>.*)/(?P<p2>.*)$', views.layui2),
03-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值