From b9a3cad0a4932b44a42d13b6a6fe852dc7a703e8 Mon Sep 17 00:00:00 2001 From: mxjdi Date: Sat, 26 Apr 2025 22:10:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=99=A8=E6=95=B4=E5=BD=A2?= =?UTF-8?q?=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/Django5.iml | 2 +- .idea/misc.xml | 2 +- Django5/urls.py | 14 ++++++++++++++ helloWorld/mymid/__init__.py | 0 helloWorld/templates/index2.html | 5 ++++- helloWorld/views.py | 8 ++++++++ 6 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 helloWorld/mymid/__init__.py diff --git a/.idea/Django5.iml b/.idea/Django5.iml index 43f1d76..e92f650 100644 --- a/.idea/Django5.iml +++ b/.idea/Django5.iml @@ -16,7 +16,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index 81a3329..ed94631 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/Django5/urls.py b/Django5/urls.py index 985ac4e..481df0c 100644 --- a/Django5/urls.py +++ b/Django5/urls.py @@ -24,6 +24,20 @@ import helloWorld.views urlpatterns = [ path('admin/', admin.site.urls), path('index/', helloWorld.views.index), + # 路由变量类型有字符类型,整型,slug和uuid + # 字符类型:匹配任何非空字符串,但不包含斜杆,如果没有指定类型,默认使用该类型 + # 整形:匹配0和正整数 + # slug可理解为注释、后缀或附属等概念,常作为路由的解析性字符 + # uuid匹配一个uuid格式的对象,为了防止冲突必须使用小写字母 + + # 使用字符类型 + # http://localhost:8000/blog/22 + path('blog/', helloWorld.views.blog), + + # 加上日期 + #http://localhost:8000/blog2/2025/4/26/80 + path('blog2////', helloWorld.views.blog2), + # 媒体路由 re_path('media/(?P.*)', serve, {'document_root': settings.MEDIA_ROOT}, name='media'), ] diff --git a/helloWorld/mymid/__init__.py b/helloWorld/mymid/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/helloWorld/templates/index2.html b/helloWorld/templates/index2.html index 540e743..b0461c2 100644 --- a/helloWorld/templates/index2.html +++ b/helloWorld/templates/index2.html @@ -7,4 +7,7 @@ 应用内模板 - \ No newline at end of file + + + + diff --git a/helloWorld/views.py b/helloWorld/views.py index 3de4d97..4515002 100644 --- a/helloWorld/views.py +++ b/helloWorld/views.py @@ -1,3 +1,4 @@ +from django.http import HttpResponse from django.shortcuts import render @@ -5,3 +6,10 @@ from django.shortcuts import render def index(request): print("页面请求处理中") return render(request, 'index.html') + + +def blog(request, id): + return HttpResponse("id是" + str(id) + "的博客页面") + +def blog2(request, year, month, day, id): + return HttpResponse(str(year) + '/' + str(month) + '/' + str(day) + '/' + ' id是' + str(id) + "的博客页面")