1、路由系统基本格式
urlpatterns = [
path( 要匹配的路径(可以是正则表达式), 视图函数, 参数, 别名)
2、参数说明
(1) 正则表达式:一个正则表达式字符串
(2) 视图函数:一个可调用对象,通常为一个视图函数或一个指定视图函数路径的字符串
(3) •参数:要传递给视图函数的默认参数(字典形式,可选)
(4) •别名:一个可选的name参数
3、正则表达式详解
(1) 在python中使用 re_path模块来写正则表达式
(2) 正则表达式的开始使用“^”表示。
(3) 正则表达式的结束使用“$”表示。
(4) “r” 元字符串 防止正则表达式中的转义。
urls.py

"""day03Django URL ConfigurationThe `urlpatterns` list routes URLs to views. For more information please see:https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views1. Add an import:  from my_app import views2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views1. Add an import:  from other_app.views import Home2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf1. Import the include() function: from django.urls import include, path2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from day03Django  import views
from  django.urls  import  path,re_path
urlpatterns = [path('admin/', admin.site.urls),
path('laowang1/', views.laowang1),
path('laowang2/', views.laowang2),
path('laowang3/', views.laowang3),
re_path(r'^laowang4/$',views.laowang4),
re_path(r'^$',views.laowang5),#匹配一个空路径  例如:http://127.0.0.1:8000/
re_path(r'^laowang6',views.laowang6),#不设置结尾,可以匹配多个路径 如http://127.0.0.1:8000/laowang6/tianzhu/le
re_path(r'^[a-zA-Z][a-zA-Z][0-9]',views.laowang7),#正则表达式
re_path(r'^laowang8/(\d+)/$',views.laowang8),
re_path(r'^laowang9/(?P<year>[0-9]{4})/$',views.laowang9),#?必须是英文问号
re_path(r'^laowang10/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$',views.laowang10),
re_path(r'^laowang11/(?P<year>[0-9]{4})/$',views.laowang11),#记住写括号
re_path(r'^laowang12/(?P<month>[0-9]{2})/$',views.laowang12,{'year':'2019'}),#记住写括号#在网站内不能修改re_path(r'^laowang13/$',views.laowang13),#记住写括号
re_path(r'^laowang14/$',views.laowang14,name='lw14'),#记住写括号
re_path(r'^laowang15/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$',views.laowang15,name='lw15'),
#\d表示任意数字,+代表至少初夏一次
#上下移动代码:shift+ctrl+上下键
#ctrl+d复制最后一行或选中的内容
#ctrl+z撤销
]

views.py

from  django.shortcuts import HttpResponse,render
def  laowang1(request):return render(request,'laowang1.html',{'name':'天主极乐大帝'})
def  laowang2(request):return  render(request,'laowang2.html',{'name':'天主极乐大帝'})
def  laowang3(request):return  render(request,'laowang3.html',{'name':'天主极乐大帝'})
def  laowang4(request):return  render(request,'laowang4.html',{'name':'天主极乐大帝'})
def  laowang5(request):return  render(request,'laowang5.html')
def  laowang6(request):return  render(request,'laowang6.html')
def  laowang7(request):return  render(request,'laowang7.html')
def  laowang8(request,num):""":param request::param num::return:"""print(num)print(type(num))return  render(request,'laowang8.html')
def  laowang9(request,year):print(year)return  render(request,'laowang9.html')
def  laowang10(request,month,year):print(year,month)return  render(request,'laowang10.html')
def  laowang11(request,year='2019'):#默认参数必须是字符串类型print(year)return  render(request,'laowang11.html',{'year':year})
def  laowang12(request,month,year):print(year,month)return  render(request,'laowang12.html',{'year':year,'month':month})
def  laowang13(request):return  render(request,'laowang13.html')
def  laowang14(request):return  render(request,'laowang14.html')
def  laowang15(request,month,year):print(type(month))return  render(request,'laowang15.html',{'year':year,'month':month})

laowang13.html

from  django.shortcuts import HttpResponse,render
def  laowang1(request):return render(request,'laowang1.html',{'name':'天主极乐大帝'})
def  laowang2(request):return  render(request,'laowang2.html',{'name':'天主极乐大帝'})
def  laowang3(request):return  render(request,'laowang3.html',{'name':'天主极乐大帝'})
def  laowang4(request):return  render(request,'laowang4.html',{'name':'天主极乐大帝'})
def  laowang5(request):return  render(request,'laowang5.html')
def  laowang6(request):return  render(request,'laowang6.html')
def  laowang7(request):return  render(request,'laowang7.html')
def  laowang8(request,num):""":param request::param num::return:"""print(num)print(type(num))return  render(request,'laowang8.html')
def  laowang9(request,year):print(year)return  render(request,'laowang9.html')
def  laowang10(request,month,year):print(year,month)return  render(request,'laowang10.html')
def  laowang11(request,year='2019'):#默认参数必须是字符串类型print(year)return  render(request,'laowang11.html',{'year':year})
def  laowang12(request,month,year):print(year,month)return  render(request,'laowang12.html',{'year':year,'month':month})
def  laowang13(request):return  render(request,'laowang13.html')
def  laowang14(request):return  render(request,'laowang14.html')
def  laowang15(request,month,year):print(type(month))return  render(request,'laowang15.html',{'year':year,'month':month})

laowang14.html

from  django.shortcuts import HttpResponse,render
def  laowang1(request):return render(request,'laowang1.html',{'name':'天主极乐大帝'})
def  laowang2(request):return  render(request,'laowang2.html',{'name':'天主极乐大帝'})
def  laowang3(request):return  render(request,'laowang3.html',{'name':'天主极乐大帝'})
def  laowang4(request):return  render(request,'laowang4.html',{'name':'天主极乐大帝'})
def  laowang5(request):return  render(request,'laowang5.html')
def  laowang6(request):return  render(request,'laowang6.html')
def  laowang7(request):return  render(request,'laowang7.html')
def  laowang8(request,num):""":param request::param num::return:"""print(num)print(type(num))return  render(request,'laowang8.html')
def  laowang9(request,year):print(year)return  render(request,'laowang9.html')
def  laowang10(request,month,year):print(year,month)return  render(request,'laowang10.html')
def  laowang11(request,year='2019'):#默认参数必须是字符串类型print(year)return  render(request,'laowang11.html',{'year':year})
def  laowang12(request,month,year):print(year,month)return  render(request,'laowang12.html',{'year':year,'month':month})
def  laowang13(request):return  render(request,'laowang13.html')
def  laowang14(request):return  render(request,'laowang14.html')
def  laowang15(request,month,year):print(type(month))return  render(request,'laowang15.html',{'year':year,'month':month})

laowang15.html

<!DOCTYPE html>
{# 加载static标签 #}
{#{% load  static %}#}
{#{% load  static %}{# load负载,装载量 #}
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>老王15-->
{{ year }}-->{{ month }}
<a  href="/laowang13/">调转到13</a></body>
</html>

Django路由系统相关推荐

  1. Python学习---Django路由系统【all】

    Django URL (路由系统) Django URL (路由系统): URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL模式以及要为该URL模式调用的视图函数之间的映 ...

  2. Python笔记——Django路由系统

    1.创建Django程序 django-admin startproject mysite 创建projectpython manage.py startapp app01 创建app01 pytho ...

  3. Django - 路由系统

    主要内容 1. URLconf配置 2.命名URL和URL反向解析 3.namespace  4.路由系统的本质(路由的分发) 1. URLconf配置 1.1 基本格式 from django.co ...

  4. django框架--路由系统

    目录 一.路由系统理解 二.路由系统功能划分 三.路由表创建 创建工具 二级路由 路由别名 动态路由及重定向 四.自定义错误页面 五.图示路由系统在框架中的定位 六.路由系统的进阶想法 一.路由系统理 ...

  5. django目录下的路由系统和视图函数

    一.Django路由系统(url) 1.什么是路由系统 路由系统的本质是URL模式以及要为该URL模式调用的视图函数之间的一个映射表即不同的url路径对应的不同的函数,该路由系统是存放在全局配置文件u ...

  6. 13.Django之url路由系统初探(一)

    一.什么是django中的url路由系统? django中的url路由系统的本质就是简历某个URL与某个视图(view)函数的对应(映射表)关系表,用下面这种特定的方式来告诉django这个web框架 ...

  7. Django的路由系统

    Django的路由系统 url配置就像Django所支撑网站的目录.它的本质是url与要为url调用的试图函数之间的映射表. 我们就是以这种方式告诉Django,遇到哪个URL的时候,要应对执行哪个函 ...

  8. Django之路由系统

    创建APP 一个Django项目可以分为很多个APP,用来隔离不同功能模块的代码. 命令行创建 python manage.py startapp app01 使用PyCharm创建 在下方弹出的命令 ...

  9. python路由编程_Python Django基础二之URL路由系统

    MVC和MTV框架 MVC Web服务器开发领域里著名的MVC模式,所谓MVC就是把Web应用分为模型(M),控制器(C)和视图(V)三层,他们之间以一种插件式的.松耦合的方式连接在一起,模型负责业务 ...

最新文章

  1. 2014年个人工作总结
  2. STORM_0001_用vmware拷贝出三个相同的ubuntu搭建小的zookeeper集群
  3. UVA 10245 The Closest Pair Problem
  4. 图像处理与计算机视觉:基础,经典以及最近发展(4)图像处理与分析
  5. Intent.FLAG_ACTIVITY_CLEAR_TOP 的使用注意
  6. SSM实现导出报表为Excel
  7. Spring Security --SecurityConfig的详细配置
  8. 学习Direct3D(五)应用程序入口
  9. 大数据实战之环境搭建(三)
  10. 面试题:Android 为什么设计只有主线程更新UI
  11. 菠萝罐头的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
  12. 孙子兵法始计篇读后感&心得(下)
  13. SAP成本核算中的作业价格计算过程实例
  14. javaSE基础大全--知识点总结
  15. 理论篇:如何理解51%攻击
  16. 2021-09-26 计科 许佳怡
  17. 跳动公差与其他几何公差(一)
  18. 查看ubuntu系统的版本信息
  19. 记应聘:华为 可信理论、技术与工程实验室 产品数据工程师
  20. 求3000以内的亲密数

热门文章

  1. troubleshoot之:分析OutOfMemoryError异常
  2. Scala教程之:可扩展的scala
  3. python做一个考试系统_1218Python基于Django在线考试系统设计
  4. AlphaGo:人工智能与深度学习
  5. 泛型的作用是什么?——Java系列学习笔记
  6. (最优解)L1-028 判断素数 (10分)——17行代码AC
  7. pcb设计实战与应用智能手机_机构强烈推荐+突破临界点+全球第一大PCB厂商=鹏鼎控股...
  8. 华为交换机 查看IP和MAC对应关系
  9. Mysql数据库(十一)——MHA高可用集群部署及故障切换
  10. C语言面试题分享(6)