from django.urls import path, re_path
from . import views
urlpatterns = [
path('', views.index),
re_path('(?P[0-9]{4})/(?P[0-9]{2})/(?P[0-9]{2}).html', views.mydate),
re_path('(?P[0-9]{4}).html', views.myyear, name='myyear'),
re_path('dict/(?P[0-9]{4}).htm', views.myyear_dict, {'month': '05'}, name='myyear_dict')
]
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello world")
def mydate(request, year, month, day):
return HttpResponse(str(year) +'/'+ str(month) +'/'+ str(day))
def myyear(request, year):
return render(request, 'myyear.html')
def myyear_dict(request, year, month):
return render(request, 'myyear_dict.html',{'month':month})
"""
字符串类型,变量为year
整型,变量为month
变量为day,格式为slug,ASCII字符 _ - 组成
uuid格式的对象 ,数字 小写字母 - 组成
(?P[0-9]{4})
?P 固定格式
<变量名>编写规则
[0-9]{4} 正则,长度4,取值在0-9
"""