路由器整形变量
This commit is contained in:
parent
ab3886b373
commit
b9a3cad0a4
@ -16,7 +16,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
|
||||
@ -3,5 +3,5 @@
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.12 (Django5)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (Django5)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
@ -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/<int:id>', helloWorld.views.blog),
|
||||
|
||||
# 加上日期
|
||||
#http://localhost:8000/blog2/2025/4/26/80
|
||||
path('blog2/<int:year>/<int:month>/<int:day>/<int:id>', helloWorld.views.blog2),
|
||||
|
||||
# 媒体路由
|
||||
re_path('media/(?P<path>.*)', serve, {'document_root': settings.MEDIA_ROOT}, name='media'),
|
||||
]
|
||||
|
||||
0
helloWorld/mymid/__init__.py
Normal file
0
helloWorld/mymid/__init__.py
Normal file
@ -8,3 +8,6 @@
|
||||
应用内模板
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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) + "的博客页面")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user