我的模板没有传递参数,也不会报告错误,但是参数会错误地报告,请帮助我。
我的urls.py是:
from django.urls import re_path
from FOUR import views
app_name = "four"
urlpatterns = [
re_path(r'mmmm', views.mmmm, name='mmmm'),
re_path(r'gettime/(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)/$', views.gettime, name='gettime'),
]
我的views.py是:
def mmmm(request):
return render(request, 'test3.html')
def gettime(request, year, day, month):
return HttpResponse("time is %s-%s-%s" % (year, month, day))
我的html是:
<a href="{ % url 'aaa:mmmm' % }">mmmmm</a><br>
<a href="{ % url 'gettime' year=2019 month=12 day=18 %}">cmdb/userinfo/tom/tomnickname/10</a><br>
mmmmm正常,cmdb / userinfo / tom / tomnickname / 10会发生以下错误
错误:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/FOUR/index/%7B%20%25%20url%20'gettime'%20year%3D2019%20month%3D12%20day%3D18%20%25%20%7D
Using the URLconf defined in HelloDjango.urls, Django tried these URL patterns, in this order:
admin/
APP/
TWO/
THREE
FOUR/ index/$
FOUR/ index/(\d+)
FOUR/ putstudent/$
FOUR/ mmmm [name='mmmm']
FOUR/ gettime/(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)/$ [name='gettime']
The current path, FOUR/index/{ % url 'gettime' year=2019 month=12 day=18 % }, didn't match any of these.
答案 0 :(得分:0)
在url标记中{
和%
之间有一个多余的空格,因此Django无法识别它。删除那些。