From c7aad21e87817247f439695330bc647907844dc1 Mon Sep 17 00:00:00 2001 From: mxjdi Date: Sat, 26 Apr 2025 22:26:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AD=A3=E5=88=99=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Django5/urls.py | 4 ++++ helloWorld/views.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Django5/urls.py b/Django5/urls.py index 481df0c..28a489f 100644 --- a/Django5/urls.py +++ b/Django5/urls.py @@ -38,6 +38,10 @@ urlpatterns = [ #http://localhost:8000/blog2/2025/4/26/80 path('blog2////', helloWorld.views.blog2), + # 正则路由 + # http://localhost:8000/blog3/2025/04/26 + re_path('blog3/(?P[0-9]{4})/(?P[0-9]{2})/(?P[0-9]{2})', helloWorld.views.blog3), + # 媒体路由 re_path('media/(?P.*)', serve, {'document_root': settings.MEDIA_ROOT}, name='media'), ] diff --git a/helloWorld/views.py b/helloWorld/views.py index 4515002..0003a91 100644 --- a/helloWorld/views.py +++ b/helloWorld/views.py @@ -13,3 +13,6 @@ def blog(request, id): def blog2(request, year, month, day, id): return HttpResponse(str(year) + '/' + str(month) + '/' + str(day) + '/' + ' id是' + str(id) + "的博客页面") + +def blog3(request, year, month, day): + return HttpResponse(str(year) + '/' + str(month) + '/' + str(day) + "的博客页面")