V
V
Vova1357982021-04-05 14:39:04
Django
Vova135798, 2021-04-05 14:39:04

How to fix Page not found error?

For some reason, an error pops up when going to the page for a separate category (/category/2 for example).
Error: 606b2d56c77a5579376448.png

Urls:

from django.urls import path
from . views import *

urlpatterns = [
    path('', news),
    path('category/<int:category_id>/', get_category)
]


views:
from django.shortcuts import render
from django.http import HttpResponse

from .models import News, Category


def news(request):
    news = News.objects.all()
    categories = Category.objects.all()
    context = {
        'news': news,
        'title':'Список новостей',
        'categories': categories,
    }
    return render(request, template_name='news/index.html', context=context)

def get_category(request, category_id):
    news = News.objects.filter(category_id=category_id)
    categories = Category.objects.all()
    Category = Category.objects.get(pk=category_id)
    return render(request, 'news/category.html', {'news': news, 'categories':categories, 'category':category})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Misha Tarasov, 2021-04-05
@Miha_Tarasov

Interesting, somewhere I just saw this question on stackoverflow :) I already wrote to you there, you can look, but if you answer briefly, you forgot the slash at the end!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question