大家好,我收到此错误:
这是我的主要网址:
urlpatterns = [
path('admin/', admin.site.urls),
path('blog/',include('blog.urls',namespace='blog')),
]
我的博客/url.py:
app_name = 'blog'
urlpatterns = [
path('',views.PostListView.as_view(), name='post_list'),
path('<int:year>/<int:month>/<int:day>/<int:post>',views.post_detail,name='post_detail'),
]
视图.py:
class PostListView(ListView):
queryset = Post.published.all()
context_object_name = 'posts'
paginate_by = 3
template_name = 'blog/post/list.html'
def post_list(request):
posts = Post.published.all()
return render(request, 'blog/post/list.html', {'posts': posts})
def post_detail(request, year, month, day, post):
post = get_object_or_404(Post, slug=post,
status='published',publish__year=year,publish__month=month,publish__day=day)
return render(request, 'blog/post/detail.html', {'post': post})
列表.html:
{% extends "blog/base.html" %}
{% block title %}My Blog{% endblock %}
{% block content %}
<h1>My Blog</h1>
{% for post in posts %}
<h2><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></h2>
<p class="date">Published {{ post.publish }} by {{ post.author }}</p>
{{ post.body|truncatewords:30|linebreaks }}
{% endfor %}
{% include "pagination.html" with page=page_obj %}
{% endblock %}
我不知道代码有什么问题。我需要一些帮助。