Add markdown support for flat pages

This commit is contained in:
Rodolphe Breard 2018-02-25 20:46:41 +01:00
parent 884fd4579a
commit 01c9651131
4 changed files with 27 additions and 4 deletions

View file

@ -9,6 +9,7 @@ name = "pypi"
django = "*"
python-decouple = "*"
markdown = "*"
[dev-packages]

13
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "c9096173a460c37db5cae58c8f61c3371b5e1fe5d436ccc27c29091ebd06fc4f"
"sha256": "afe4d05c7a34f361ac700b159c1844aab93669730285b054bf92bbf33bd5ff60"
},
"host-environment-markers": {
"implementation_name": "cpython",
@ -9,9 +9,9 @@
"os_name": "posix",
"platform_machine": "x86_64",
"platform_python_implementation": "CPython",
"platform_release": "4.15.1-2-ARCH",
"platform_release": "4.15.4-1-ARCH",
"platform_system": "Linux",
"platform_version": "#1 SMP Sun Feb 4 22:27:45 UTC 2018",
"platform_version": "#1 SMP PREEMPT Sat Feb 17 16:01:38 UTC 2018",
"python_full_version": "3.6.4",
"python_version": "3.6",
"sys_platform": "linux"
@ -34,6 +34,13 @@
],
"version": "==2.0.2"
},
"markdown": {
"hashes": [
"sha256:9ba587db9daee7ec761cfc656272be6aabe2ed300fece21208e4aab2e457bc8f",
"sha256:a856869c7ff079ad84a3e19cd87a64998350c2b94e9e08e44270faef33400f81"
],
"version": "==2.6.11"
},
"python-decouple": {
"hashes": [
"sha256:1317df14b43efee4337a4aa02914bf004f010cd56d6c4bd894e6474ec8c4fe2d"

View file

@ -1,5 +1,6 @@
from django.conf import settings
from django.db import models
import markdown
class Page(models.Model):
@ -18,5 +19,19 @@ class PageContent(models.Model):
title = models.CharField(max_length=200)
content = models.TextField()
def formated_content(self):
return markdown.markdown(
self.content,
extensions=[
'markdown.extensions.extra',
'markdown.extensions.admonition',
'markdown.extensions.nl2br',
'markdown.extensions.sane_lists',
'markdown.extensions.smarty',
'markdown.extensions.toc',
],
output_format='html5',
)
def __str__(self):
return self.title

View file

@ -3,5 +3,5 @@
{% block title %}{{ page.title }}{% endblock %}
{% block content %}
{{ page.content|safe }}
{{ page.formated_content|safe }}
{% endblock %}