Django template engine to render untrusted template code
Django 3.0 to 5.0
from django.template import Template
from django_safe_template_engine.engine import SafeTemplateEngine
safe_engine = SafeTemplateEngine()
Template(source, engine=safe_engine)
from django_safe_template_engine.validators import validate_safe_engine_template_syntax
template_code = '{% include "hacked.html" %}'
validate_safe_engine_template_syntax(template_code)
The following tags and filters are allowed by this template engine.
autoescape
comment
cycle
filter
firstof
for
for … empty
if
ifchanged
lorem
now
regroup
resetcycle
spaceless
templatetag
url
verbatim
widthratio
with
add
addslashes
capfirst
center
cut
date
default_if_none
default
dictsort
dictsortreversed
divisibleby
escape
escapejs
filesizeformat
first
floatformat
force_escape
get_digit
iriencode
join
json_script
last
length_is
length
linebreaks
linebreaksbr
linenumbers
ljust
lower
make_list
phone2numeric
pluralize
random
rjust
safe
safeseq
slice
slugify
stringformat
striptags
time
timesince
timeuntil
title
truncatechars_html
truncatechars
truncatewords_html
truncatewords
unordered_list
upper
urlencode
urlize
urlizetrunc
wordcount
wordwrap
yesno
You want to add awesome features to Django Safe Template Engine? Here's how!
- Fork this repository
- Commit and push to your forked repository
- Open a pull request to merge your work into this repository
You can use tox to run the code formatting / type checking tools, and run the test suite:
tox run
For a more relevant git blame you can set up your git to use the file .git-blame-ignore-revs
in blame.ignoreRevsFile
:
git config blame.ignoreRevsFile .git-blame-ignore-revs