本文整理汇总了Python中django_jinja.backend.Jinja2类的典型用法代码示例。如果您正苦于以下问题:Python Jinja2类的具体用法?Python Jinja2怎么用?Python Jinja2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Jinja2类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_default_none
def test_get_default_none(self):
from django.conf import global_settings
from django_jinja.backend import Jinja2
with self.settings(TEMPLATES=global_settings.TEMPLATES):
with self.assertRaisesRegexp(ImproperlyConfigured, r'No Jinja2 backend is configured'):
Jinja2.get_default()
示例2: test_get_default_multiple
def test_get_default_multiple(self):
from django_jinja.backend import Jinja2
with self.modify_settings(TEMPLATES={
'append': [{"BACKEND": "django_jinja.backend.Jinja2",
"NAME": "jinja2dup",
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
],
"constants": {
"foo": "bar",
},
"extensions": settings.JINJA2_EXTENSIONS
}}],
}):
with self.assertRaisesRegexp(ImproperlyConfigured, r'Several Jinja2 backends are configured'):
Jinja2.get_default()
示例3: test_get_match_extension
def test_get_match_extension(self):
if django.VERSION[:2] < (1, 8):
self.assertEquals(getattr(settings, "DEFAULT_JINJA2_TEMPLATE_EXTENSION", ".jinja"), get_match_extension())
else:
from django_jinja.backend import Jinja2
self.assertEquals(Jinja2.get_default().match_extension, get_match_extension())
示例4: test_get_default_multiple
def test_get_default_multiple(self):
from django_jinja.backend import Jinja2
setting = {
"append": [
{
"BACKEND": "django_jinja.backend.Jinja2",
"NAME": "jinja2dup",
"APP_DIRS": True,
"OPTIONS": {"match_extension": ".jinjadup"},
}
]
}
with self.modify_settings(TEMPLATES=setting):
with self.assertRaisesRegexp(ImproperlyConfigured, r"Several Jinja2 backends"):
Jinja2.get_default()
示例5: TestRender
import os
from django.test import TestCase
from django.test.client import RequestFactory
from django.test.utils import override_settings
from django_jinja.backend import Jinja2
from mock import patch
from lib import l10n_utils
ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_files')
TEMPLATE_DIRS = (os.path.join(ROOT, 'templates'),)
jinja_env = Jinja2.get_default()
@patch.object(jinja_env.env.loader, 'searchpath', TEMPLATE_DIRS)
@override_settings(ROOT=ROOT)
@override_settings(DEV=False)
class TestRender(TestCase):
urls = 'lib.l10n_utils.tests.test_files.urls'
def _test(self, path, template, locale, accept_lang, status, destination=None,
active_locales=None, add_active_locales=None):
request = RequestFactory().get(path)
request.META['HTTP_ACCEPT_LANGUAGE'] = accept_lang
request.locale = locale
ctx = {}
if active_locales:
ctx['active_locales'] = active_locales
示例6: test_get_default
def test_get_default(self):
from django_jinja.backend import Jinja2
Jinja2.get_default.cache_clear()
self.assertEqual(Jinja2.get_default(), self.env)
示例7: TestDjangoJinjaMarkdown
from django.test import TestCase
from django_jinja.backend import Jinja2
engine = Jinja2.get_default()
class TestDjangoJinjaMarkdown(TestCase):
def test_markdown_filter(self):
self.assertEqual(engine.from_string('{{ "**bold dude**"|markdown }}').render(),
'<p><strong>bold dude</strong></p>')
def test_markdown_function(self):
self.assertEqual(engine.from_string('{{ markdown("***angry walter***") }}').render(),
'<p><strong><em>angry walter</em></strong></p>')
def test_markdown_tag(self):
self.assertEqual(engine.from_string('{% markdown %}*fancy donnie*{% endmarkdown %}').render(),
'<p><em>fancy donnie</em></p>')