formation_django/exemple/mon_site/blog/views.py
2018-04-10 11:29:01 +02:00

12 lines
422 B
Python

from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from .models import Article
def index(request):
articles = Article.objects.order_by('-date')
return render(request, 'blog/list_articles.html', {'articles':articles})
def view_article(request, pk):
article = get_object_or_404(Article, pk=pk)
return render(request, 'blog/view_article.html', {'article':article})