Commit 915f2289 authored by Sli's avatar Sli

Ajout de la sélection des articles

parent e2394117
......@@ -22,3 +22,6 @@ class Article(models.Model):
def save(self, *args, **kwargs):
SlugUnique.unique_slugify(self, self.title)
super(Article, self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse('article', args=[self.slug])
<!DOCTYPE html>
{% load markdown_deux_tags %}
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<h1>{{article.title}}</h1>
{% markdown %}
{{article.content}}
{% endmarkdown %}
</body>
</html>
\ No newline at end of file
......@@ -9,7 +9,9 @@
{% for article in articles %}
<h1>{{article.title}}</h1>
<a href="{{article.get_absolute_url}}">
<h1>{{article.title|title}}</h1>
</a>
{% markdown %}
{{article.content}}
......
......@@ -2,13 +2,13 @@
# @Author: klmp200
# @Date: 2016-06-04 23:24:06
# @Last Modified by: klmp200
# @Last Modified time: 2016-06-04 23:40:24
# @Last Modified time: 2016-06-06 13:19:24
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf.urls import patterns, url
urlpatterns = patterns('blog.views',
url(r'^$', 'blog', name='blog'),
url(r'^article/(?P<slug>.+)$', 'article', name='article'),
)
\ No newline at end of file
#-*- coding: utf-8 -*-
from django.shortcuts import render
from django.shortcuts import render, get_object_or_404
from blog.models import Article
......@@ -7,3 +7,10 @@ def blog(request):
articles = Article.objects.exclude(published=False).order_by('-date')
return render(request, 'blog/blog.html', {'articles': articles})
def article(request, slug):
article = get_object_or_404(Article, slug=slug, published=True)
return render(request, 'blog/article.html', {'article': article})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment