Use jinja2 for templating
This commit is contained in:
parent
a84bae8f04
commit
703099f02b
5 changed files with 18 additions and 5 deletions
|
@ -4,3 +4,4 @@ gunicorn
|
|||
markdown
|
||||
chrono
|
||||
django-debug-toolbar
|
||||
django-jinja
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
</head>
|
||||
<body>
|
||||
{{ page.toc.html|safe }}
|
||||
{{ content }}
|
||||
{{ content|safe }}
|
||||
</body>
|
|
@ -1,7 +1,8 @@
|
|||
from django.db import models
|
||||
import markdown
|
||||
from django.template import Template
|
||||
from django.utils.functional import cached_property
|
||||
from django.template import engines
|
||||
from django_jinja.backend import Origin
|
||||
|
||||
class Tag(models.Model):
|
||||
__yamdl__ = True
|
||||
|
@ -50,5 +51,7 @@ class Page(models.Model):
|
|||
@cached_property
|
||||
def content_template(self):
|
||||
if (cached_template := self._template_cache.get(self.slug)) is None:
|
||||
cached_template = self._template_cache[self.slug] = Template(self.content, name=self.slug)
|
||||
cached_template = self._template_cache[self.slug] = engines["jinja2"].from_string(self.content)
|
||||
cached_template.origin = Origin(name=self.slug, template_name=self.slug)
|
||||
cached_template.name = self.slug
|
||||
return cached_template
|
||||
|
|
|
@ -19,7 +19,7 @@ def content(request, slug):
|
|||
|
||||
return render(request, "content.html", {
|
||||
"page": page,
|
||||
"content": page.content_template.render(Context({"request": request, "page": page}))
|
||||
"content": page.content_template.render({"request": request, "page": page})
|
||||
})
|
||||
|
||||
cached_content = cache_page(600, cache="mem")(content)
|
||||
|
|
|
@ -25,7 +25,7 @@ SECRET_KEY = 'django-insecure-13rey)pheg9^%jtworn_&3wl&$-l%40uza0!ijva+l$n5umuz3
|
|||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
|
||||
|
||||
# Application definition
|
||||
|
@ -59,6 +59,15 @@ TEMPLATES = [
|
|||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
'BACKEND': 'django_jinja.jinja2.Jinja2',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'app_dirname': "jinja2",
|
||||
"match_extension": ".html"
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'yamdl_playground.wsgi.application'
|
||||
|
|
Loading…
Reference in a new issue