Answer the question
In order to leave comments, you need to log in
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:
Urls:
from django.urls import path
from . views import *
urlpatterns = [
path('', news),
path('category/<int:category_id>/', get_category)
]
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
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 questionAsk a Question
731 491 924 answers to any question