当前位置: 首页>>代码示例>>Python>>正文


Python aiohttp_jinja2.template方法代码示例

本文整理汇总了Python中aiohttp_jinja2.template方法的典型用法代码示例。如果您正苦于以下问题:Python aiohttp_jinja2.template方法的具体用法?Python aiohttp_jinja2.template怎么用?Python aiohttp_jinja2.template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aiohttp_jinja2的用法示例。


在下文中一共展示了aiohttp_jinja2.template方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_url_with_query

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_url_with_query(aiohttp_client):

    @aiohttp_jinja2.template('tmpl.jinja2')
    async def index(request):
        return {}

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
        {'tmpl.jinja2':
         "{{ url('index', query_={'foo': 'bar'})}}"}))

    app.router.add_get('/', index, name='index')
    client = await aiohttp_client(app)

    resp = await client.get('/')
    assert 200 == resp.status
    txt = await resp.text()
    assert '/?foo=bar' == txt 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:20,代码来源:test_jinja_globals.py

示例2: test_url_int_param

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_url_int_param(aiohttp_client):

    @aiohttp_jinja2.template('tmpl.jinja2')
    async def index(request):
        return {}

    async def other(request):
        return

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
        {'tmpl.jinja2':
         "{{ url('other', arg=1)}}"}))

    app.router.add_route('GET', '/', index)
    app.router.add_route('GET', '/uid/{arg}', other, name='other')
    client = await aiohttp_client(app)

    resp = await client.get('/')
    assert 200 == resp.status
    txt = await resp.text()
    assert '/uid/1' == txt 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:24,代码来源:test_jinja_globals.py

示例3: test_static

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_static(aiohttp_client):

    @aiohttp_jinja2.template('tmpl.jinja2')
    async def index(request):
        return {}

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
        {'tmpl.jinja2':
         "{{ static('whatever.js') }}"}))

    app['static_root_url'] = '/static'
    app.router.add_route('GET', '/', index)
    client = await aiohttp_client(app)

    resp = await client.get('/')
    assert 200 == resp.status
    txt = await resp.text()
    assert '/static/whatever.js' == txt 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:21,代码来源:test_jinja_globals.py

示例4: test_func

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_func(aiohttp_client):

    @aiohttp_jinja2.template('tmpl.jinja2')
    async def func(request):
        return {'head': 'HEAD', 'text': 'text'}

    template = '<html><body><h1>{{head}}</h1>{{text}}</body></html>'
    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader({
        'tmpl.jinja2': template
    }))

    app.router.add_route('*', '/', func)

    client = await aiohttp_client(app)

    resp = await client.get('/')
    assert 200 == resp.status
    txt = await resp.text()
    assert '<html><body><h1>HEAD</h1>text</body></html>' == txt 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:22,代码来源:test_simple_renderer.py

示例5: test_render_class_based_view

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_render_class_based_view(aiohttp_client):
    class MyView(web.View):
        @aiohttp_jinja2.template('tmpl.jinja2')
        async def get(self):
            return {'head': 'HEAD', 'text': 'text'}

    template = '<html><body><h1>{{head}}</h1>{{text}}</body></html>'

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader({
        'tmpl.jinja2': template
    }))

    app.router.add_route('*', '/', MyView)

    client = await aiohttp_client(app)

    resp = await client.get('/')

    assert 200 == resp.status
    txt = await resp.text()
    assert '<html><body><h1>HEAD</h1>text</body></html>' == txt 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:24,代码来源:test_simple_renderer.py

示例6: test_convert_func_to_coroutine

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_convert_func_to_coroutine(aiohttp_client):

    @aiohttp_jinja2.template('tmpl.jinja2')
    async def func(request):
        return {'head': 'HEAD', 'text': 'text'}

    template = '<html><body><h1>{{head}}</h1>{{text}}</body></html>'

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader({
        'tmpl.jinja2': template
    }))

    app.router.add_route('*', '/', func)

    client = await aiohttp_client(app)

    resp = await client.get('/')

    txt = await resp.text()
    assert '<html><body><h1>HEAD</h1>text</body></html>' == txt 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:23,代码来源:test_simple_renderer.py

示例7: test_render_not_initialized

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_render_not_initialized():

    async def func(request):
        return aiohttp_jinja2.render_template('template', request, {})

    app = web.Application()

    app.router.add_route('GET', '/', func)

    req = make_mocked_request('GET', '/', app=app)
    msg = "Template engine is not initialized, " \
          "call aiohttp_jinja2.setup(..., app_key={}" \
          ") first".format(aiohttp_jinja2.APP_KEY)

    with pytest.raises(web.HTTPInternalServerError) as ctx:
        await func(req)

    assert msg == ctx.value.text 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:20,代码来源:test_simple_renderer.py

示例8: test_set_status

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_set_status(aiohttp_client):

    @aiohttp_jinja2.template('tmpl.jinja2', status=201)
    async def func(request):
        return {'head': 'HEAD', 'text': 'text'}

    template = '<html><body><h1>{{head}}</h1>{{text}}</body></html>'

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader({
        'tmpl.jinja2': template
    }))

    app.router.add_route('*', '/', func)

    client = await aiohttp_client(app)

    resp = await client.get('/')

    assert 201 == resp.status
    txt = await resp.text()
    assert '<html><body><h1>HEAD</h1>text</body></html>' == txt 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:24,代码来源:test_simple_renderer.py

示例9: test_render_template

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_render_template(aiohttp_client):

    async def func(request):
        return aiohttp_jinja2.render_template(
            'tmpl.jinja2', request,
            {'head': 'HEAD', 'text': 'text'})

    template = '<html><body><h1>{{head}}</h1>{{text}}</body></html>'

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader({
        'tmpl.jinja2': template
    }))

    app.router.add_route('*', '/', func)

    client = await aiohttp_client(app)

    resp = await client.get('/')

    assert 200 == resp.status
    txt = await resp.text()
    assert '<html><body><h1>HEAD</h1>text</body></html>' == txt 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:25,代码来源:test_simple_renderer.py

示例10: test_render_template_custom_status

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_render_template_custom_status(aiohttp_client):

    async def func(request):
        return aiohttp_jinja2.render_template(
            'tmpl.jinja2', request,
            {'head': 'HEAD', 'text': 'text'}, status=404)

    template = '<html><body><h1>{{head}}</h1>{{text}}</body></html>'

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader({
        'tmpl.jinja2': template
    }))

    app.router.add_route('*', '/', func)

    client = await aiohttp_client(app)

    resp = await client.get('/')

    assert 404 == resp.status
    txt = await resp.text()
    assert '<html><body><h1>HEAD</h1>text</body></html>' == txt 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:25,代码来源:test_simple_renderer.py

示例11: test_render_not_mapping

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_render_not_mapping():

    @aiohttp_jinja2.template('tmpl.jinja2')
    async def func(request):
        return 123

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
        {'tmpl.jinja2': 'tmpl'}))

    app.router.add_route('GET', '/', func)

    req = make_mocked_request('GET', '/', app=app)
    msg = "context should be mapping, not <class 'int'>"
    with pytest.raises(web.HTTPInternalServerError) as ctx:
        await func(req)

    assert msg == ctx.value.text 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:20,代码来源:test_simple_renderer.py

示例12: test_render_without_context

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_render_without_context(aiohttp_client):

    @aiohttp_jinja2.template('tmpl.jinja2')
    async def func(request):
        pass

    template = '<html><body><p>{{text}}</p></body></html>'

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
        {'tmpl.jinja2': template}))

    app.router.add_route('GET', '/', func)

    client = await aiohttp_client(app)
    resp = await client.get('/')

    assert 200 == resp.status
    txt = await resp.text()
    assert '<html><body><p></p></body></html>' == txt 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:22,代码来源:test_simple_renderer.py

示例13: test_render_default_is_autoescaped

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_render_default_is_autoescaped(aiohttp_client):

    @aiohttp_jinja2.template('tmpl.jinja2')
    async def func(request):
        return {'text': '<script>alert(1)</script>'}

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
        {'tmpl.jinja2': '<html>{{text}}</html>'}))

    app.router.add_route('GET', '/', func)

    client = await aiohttp_client(app)
    resp = await client.get('/')

    assert 200 == resp.status
    txt = await resp.text()
    assert '<html>&lt;script&gt;alert(1)&lt;/script&gt;</html>' == txt 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:20,代码来源:test_simple_renderer.py

示例14: test_render_can_disable_autoescape

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_render_can_disable_autoescape(aiohttp_client):

    @aiohttp_jinja2.template('tmpl.jinja2')
    async def func(request):
        return {'text': '<script>alert(1)</script>'}

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
        {'tmpl.jinja2': '<html>{{text}}</html>'}), autoescape=False)

    app.router.add_route('GET', '/', func)

    client = await aiohttp_client(app)
    resp = await client.get('/')

    assert 200 == resp.status
    txt = await resp.text()
    assert '<html><script>alert(1)</script></html>' == txt 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:20,代码来源:test_simple_renderer.py

示例15: test_jinja_filters

# 需要导入模块: import aiohttp_jinja2 [as 别名]
# 或者: from aiohttp_jinja2 import template [as 别名]
def test_jinja_filters(aiohttp_client):

    @aiohttp_jinja2.template('tmpl.jinja2')
    async def index(request):
        return {}

    def add_2(value):
        return value + 2

    app = web.Application()
    aiohttp_jinja2.setup(
        app,
        loader=jinja2.DictLoader({'tmpl.jinja2': "{{ 5|add_2 }}"}),
        filters={'add_2': add_2}
    )

    app.router.add_route('GET', '/', index)
    client = await aiohttp_client(app)

    resp = await client.get('/')
    assert 200 == resp.status
    txt = await resp.text()
    assert '7' == txt 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:25,代码来源:test_jinja_filters.py


注:本文中的aiohttp_jinja2.template方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。