Added articles to blog index view

Added article show view with url
This commit is contained in:
Émile Filteau 2015-08-01 13:05:11 -04:00
parent 7192952a48
commit 59ef29df65
3 changed files with 20 additions and 1 deletions

View File

@ -0,0 +1,7 @@
{% extends 'template.html' %}
{% block content %}
<section>
<h1>{{ article.title }}</h1>
</section>
{% endblock %}

View File

@ -3,4 +3,5 @@ from blog import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^(?P<article_id>\d+)$', views.show, name='show'),
)

View File

@ -1,5 +1,16 @@
from django.shortcuts import render
from django.http import Http404
from blog.models import Article
def index(request):
return render(request, 'blog/index.html', {})
articles = Article.objects.order_by('-created_at')
return render(request, 'blog/index.html', {'articles': articles})
def show(request, article_id):
try:
article = Article.objects.get(id=article_id)
return render(request, 'blog/show.html', {'article': article})
except Article.DoesNotExist:
raise Http404("Article does not exist")