formation_django/exemple/mon_site/blog/views.py

13 lines
422 B
Python
Raw Normal View History

2018-04-10 09:28:27 +00:00
from django.shortcuts import render, get_object_or_404
2018-04-07 13:49:12 +00:00
from django.http import HttpResponse
from .models import Article
def index(request):
articles = Article.objects.order_by('-date')
2018-04-10 09:28:27 +00:00
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})