Python 在URL.py中未检测到my Django DayArchiveView
我在Django中创建了几个基于日期的视图,虽然年视图和月视图的功能与预期相同,但没有检测到显示天数的视图。例如,如果我尝试获取Python 在URL.py中未检测到my Django DayArchiveView,python,django,django-views,Python,Django,Django Views,我在Django中创建了几个基于日期的视图,虽然年视图和月视图的功能与预期相同,但没有检测到显示天数的视图。例如,如果我尝试获取/balance/2018/,或/balance/2018/04/,将显示视图,而/balance/2018/04/02将失败。我知道问题一定出在URL.py配置上,但我在文档中找不到它。我还尝试将day_format='%d'传递给as_view方法,但没有任何结果 my URL.py文件 from django.urls import path, re_path f
/balance/2018/
,或/balance/2018/04/
,将显示视图,而/balance/2018/04/02
将失败。我知道问题一定出在URL.py配置上,但我在文档中找不到它。我还尝试将day_format='%d'传递给as_view方法,但没有任何结果
my URL.py文件
from django.urls import path, re_path
from .views import ArticleYearArchiveView, ArticleMonthArchiveView, ArticleDayArchiveView
from . import views
urlpatterns = [
path('', views.index, name='index'),
path(r'<int:year>/<int:month:>/<int:day>/', views.ArticleDayArchiveView.as_view(day_format='%d'), name='show_day'),
path(r'<int:year>/<int:month>/', views.ArticleMonthArchiveView.as_view(month_format='%m'), name='show_month'),
path(r'<int:year>/', views.ArticleYearArchiveView.as_view(), name='show_year'),
]
错误文本为:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/balance/2018/04/02
Using the URLconf defined in spendings_calculator.urls, Django tried these URL patterns, in this order:
admin/
balance/ [name='index']
balance/ <int:year>/<int:month:>/<int:day>/ [name='show_day']
balance/ <int:year>/<int:month>/ [name='show_month']
balance/ <int:year>/ [name='show_year']
The current path, balance/2018/04/02, didn't match any of these.
未找到页面(404)
请求方法:获取
请求URL:http://localhost:8000/balance/2018/04/02
Django使用spendings_calculator.URL中定义的URLconf,按以下顺序尝试了这些URL模式:
管理员/
余额/[name='index']
余额///[name='show_day']
余额//[name='show_month']
余额/[name='show_year']
当前路径balance/2018/04/02与上述任何路径都不匹配。
您在月份之后有一个流浪的
:
。删除它:
path(r'<int:year>/<int:month>/<int:day>/', views.ArticleDayArchiveView.as_view(day_format='%d'), name='show_day'),
path(r'//',views.ArticleDayArchiveView.as_视图(day_格式='%d'),name='show_day'),
另外,请注意,您正在为
balance/2018/04/02/
(带尾随斜杠)定义URL,但您将进入http://localhost:8000/balance/2018/04/02
(不带尾随斜杠)。一旦你纠正了上面的错误,Django应该将你重定向到带有尾随斜杠的URL。你有一个错误的:
在月份之后-
。删除它:
path(r'<int:year>/<int:month>/<int:day>/', views.ArticleDayArchiveView.as_view(day_format='%d'), name='show_day'),
path(r'//',views.ArticleDayArchiveView.as_视图(day_格式='%d'),name='show_day'),
另外,请注意,您正在为
balance/2018/04/02/
(带尾随斜杠)定义URL,但您将进入http://localhost:8000/balance/2018/04/02
(不带尾随斜杠)。一旦你修正了上面的输入错误,Django应该将你重定向到带有尾随斜杠的URL。oh!非常感谢你,我已经读了很多遍了,但还没有看到。哦!非常感谢,我已经读了很多遍了,还没看过。