old-website/articles/views.py

21 lines
630 B
Python
Raw Normal View History

2023-06-18 18:06:01 +00:00
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from articles.models import Article
def article_list(request):
2023-06-19 16:48:32 +00:00
articles = (Article.objects.defer('body')
.filter(published=True)
.order_by("-date")
.all())
2023-06-18 18:06:01 +00:00
return render(request, "views/articles.html", {"articles": articles})
def article_detail(request, slug):
article = get_object_or_404(Article, slug=slug)
if not article.published:
return HttpResponse("Not found")
return render(request, "views/article.html", {"article": article})