mirror of
https://gitee.com/openharmony/third_party_jinja2
synced 2024-12-04 05:23:33 +00:00
Updated examples to use Django cached.
--HG-- branch : trunk
This commit is contained in:
parent
53cafcc1ae
commit
f60232d52b
@ -103,7 +103,7 @@ try:
|
||||
except ImportError:
|
||||
test_django = None
|
||||
else:
|
||||
django_template = """\
|
||||
django_template = DjangoTemplate("""\
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
@ -131,16 +131,13 @@ else:
|
||||
</div>
|
||||
</body>
|
||||
</html>\
|
||||
"""
|
||||
""")
|
||||
|
||||
def test_django():
|
||||
c = DjangoContext(context)
|
||||
c['navigation'] = [('index.html', 'Index'), ('downloads.html', 'Downloads'),
|
||||
('products.html', 'Products')]
|
||||
# recompile template each rendering because that's what django
|
||||
# is doing in normal situations too. Django is not thread safe
|
||||
# so we can't cache it in regular apps either.
|
||||
DjangoTemplate(django_template).render(c)
|
||||
django_template.render(c)
|
||||
|
||||
try:
|
||||
from mako.template import Template as MakoTemplate
|
||||
|
@ -11,6 +11,9 @@ context = {
|
||||
}
|
||||
|
||||
source = """\
|
||||
% macro testmacro(x)
|
||||
<span>{{ x }}</span>
|
||||
% endmacro
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
@ -25,7 +28,7 @@ source = """\
|
||||
% for row in table
|
||||
<tr>
|
||||
% for cell in row
|
||||
<td>${cell}</td>
|
||||
<td>${testmacro(cell)}</td>
|
||||
% endfor
|
||||
</tr>
|
||||
% endfor
|
||||
|
@ -2,7 +2,14 @@
|
||||
from rwbench import ROOT
|
||||
from os.path import join
|
||||
from django.conf import settings
|
||||
settings.configure(TEMPLATE_DIRS=(join(ROOT, 'django'),))
|
||||
settings.configure(
|
||||
TEMPLATE_DIRS=(join(ROOT, 'django'),),
|
||||
TEMPLATE_LOADERS=(
|
||||
('django.template.loaders.cached.Loader', (
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
)),
|
||||
)
|
||||
)
|
||||
from django.template import loader as django_loader, Context as DjangoContext, \
|
||||
Node, NodeList, Variable, TokenParser
|
||||
from django import template as django_template_module
|
||||
|
Loading…
Reference in New Issue
Block a user