@freiqqqq

Почему Page not found (404)?

Не понимаю почему выходит 404, вроде все правильною

upd: при переходе на второй пост выходит
MultipleObjectsReturned at /1928/card2/second_post/28/11/2020/
get() returned more than one Post -- it returned 2!
-------------------------------------
urls.py

urlpatterns = [
    path('', views.main_page,name='main_page'),
    path('<slug:card_slug>/', views.post_list, name='post_list'),
    path('<slug:card_slug>/<slug:post>/<int:day>/<int:month>/<int:year>/', views.post_detail, name='post_detail'),
    path('<slug:card_slug>/<int:post_id>/share/', views.post_share, name='post_share'),
    path('<slug:card_slug>/<slug:tag_slug>/',views.post_list, name='post_list_by_tag'),
    path('feed/', LatestPostsFeed(), name='post_feed'),
]
----------------------------------------------------------------------------------------------------------------
views.py

def post_detail(request, day, month, year, post,card_slug , tag_slug=None):
    post = get_object_or_404(Post,  slug=post,card__slug=card_slug, status='published',
                             publish__day=day,
                             publish__month=month,
                             publish__year=year)
    tag = None
    if tag_slug:
        tag = get_object_or_404(Tag, slug=tag_slug)
    comments = post.comments.filter(active=True)
    new_comment = None
    if request.method == 'POST':
        comment_form = CommentForm(data=request.POST)
        if comment_form.is_valid():
            new_comment = comment_form.save(commit=False)
            new_comment.post = post
            new_comment.save()
            comment_form = CommentForm()
            return redirect(post)
    else:
        comment_form = CommentForm()
    return render(request, 'blog/post/detail.html', {'post':post,
                                                     'comments':comments,
                                                     'new_comment':new_comment,
                                                     'comment_form':comment_form,
                                                     'tag':tag})

-----------------------------------------
models.py 


    def get_absolute_url(self):
        return reverse('blog:post_detail', args=[self.card.slug, 
                                                 self.slug,
                                                 self.publish.day,
                                                 self.publish.month,
                                                 self.publish.year,])
  • Вопрос задан
  • 62 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы