當前位置: 首頁>>代碼示例>>Python>>正文


Python aiohttp_jinja2.render_template方法代碼示例

本文整理匯總了Python中aiohttp_jinja2.render_template方法的典型用法代碼示例。如果您正苦於以下問題:Python aiohttp_jinja2.render_template方法的具體用法?Python aiohttp_jinja2.render_template怎麽用?Python aiohttp_jinja2.render_template使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在aiohttp_jinja2的用法示例。


在下文中一共展示了aiohttp_jinja2.render_template方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_url_param_forbidden_type

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_template [as 別名]
def test_url_param_forbidden_type(aiohttp_client):

    async def index(request):
        with pytest.raises(TypeError,
                           match=(r"argument value should be str or int, "
                                  r"got arg -> \[<class 'bool'>\] True")):
            aiohttp_jinja2.render_template('tmpl.jinja2', request, {})
        return web.Response()

    async def other(request):
        return

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

    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 
開發者ID:aio-libs,項目名稱:aiohttp-jinja2,代碼行數:25,代碼來源:test_jinja_globals.py

示例2: test_helpers_disabled

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_template [as 別名]
def test_helpers_disabled(aiohttp_client):

    async def index(request):
        with pytest.raises(jinja2.UndefinedError,
                           match="'url' is undefined"):
            aiohttp_jinja2.render_template('tmpl.jinja2', request, {})
        return web.Response()

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

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

    resp = await client.get('/')
    assert 200 == resp.status 
開發者ID:aio-libs,項目名稱:aiohttp-jinja2,代碼行數:23,代碼來源:test_jinja_globals.py

示例3: test_static_var_missing

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_template [as 別名]
def test_static_var_missing(aiohttp_client, caplog):

    async def index(request):
        with pytest.raises(RuntimeError, match='static_root_url'):
            aiohttp_jinja2.render_template('tmpl.jinja2', request, {})
        return web.Response()

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

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

    resp = await client.get('/')
    assert 200 == resp.status  # static_root_url is not set 
開發者ID:aio-libs,項目名稱:aiohttp-jinja2,代碼行數:19,代碼來源:test_jinja_globals.py

示例4: test_render_not_initialized

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_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

示例5: test_render_template

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_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

示例6: test_template_not_found

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_template [as 別名]
def test_template_not_found():

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

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

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

    req = make_mocked_request('GET', '/', app=app)

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

    t = "Template 'template' not found"
    assert t == ctx.value.text
    assert t == ctx.value.reason 
開發者ID:aio-libs,項目名稱:aiohttp-jinja2,代碼行數:20,代碼來源:test_simple_renderer.py

示例7: normal

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_template [as 別名]
def normal(self, request):
        """適配瀏覽器中進行遊戲的頁麵,該頁麵會檢查會話中是否有api_token、api_starttime和world_ip三個參數,缺少其中任意一個都不能進行
        遊戲,跳轉回登錄頁麵。

        :param request: aiohttp.web.Request
        :return: aiohttp.web.Response or aiohttp.web.HTTPFound
        """
        session = yield from get_session(request)
        token = session.get('api_token', None)
        starttime = session.get('api_starttime', None)
        world_ip = session.get('world_ip', None)
        if token and starttime and world_ip:
            context = {'scheme': request.scheme,
                       'host': request.host,
                       'token': token,
                       'starttime': starttime}
            return aiohttp_jinja2.render_template('normal.html', request, context)
        else:
            self.clear_session(session)
            return aiohttp.web.HTTPFound('/') 
開發者ID:acgx,項目名稱:ooi3,代碼行數:22,代碼來源:frontend.py

示例8: kcv

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_template [as 別名]
def kcv(self, request):
        """適配KanColleViewer或者74EO中進行遊戲的頁麵,提供一個iframe,在iframe中載入遊戲FLASH。該頁麵會檢查會話中是否有api_token、
        api_starttime和world_ip三個參數,缺少其中任意一個都不能進行遊戲,跳轉回登錄頁麵。

        :param request: aiohttp.web.Request
        :return: aiohttp.web.Response or aiohttp.web.HTTPFound
        """
        session = yield from get_session(request)
        token = session.get('api_token', None)
        starttime = session.get('api_starttime', None)
        world_ip = session.get('world_ip', None)
        if token and starttime and world_ip:
            return aiohttp_jinja2.render_template('kcv.html', request, context={})
        else:
            self.clear_session(session)
            return aiohttp.web.HTTPFound('/') 
開發者ID:acgx,項目名稱:ooi3,代碼行數:18,代碼來源:frontend.py

示例9: flash

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_template [as 別名]
def flash(self, request):
        """適配KanColleViewer或者74EO中進行遊戲的頁麵,展示,該頁麵會檢查會話中是否有api_token、api_starttime和world_ip三個參數,
        缺少其中任意一個都不能進行遊戲,跳轉回登錄頁麵。

        :param request: aiohttp.web.Request
        :return: aiohttp.web.Response or aiohttp.web.HTTPFound
        """
        session = yield from get_session(request)
        token = session.get('api_token', None)
        starttime = session.get('api_starttime', None)
        world_ip = session.get('world_ip', None)
        if token and starttime and world_ip:
            context = {'scheme': request.scheme,
                       'host': request.host,
                       'token': token,
                       'starttime': starttime}
            return aiohttp_jinja2.render_template('flash.html', request, context)
        else:
            self.clear_session(session)
            return aiohttp.web.HTTPFound('/') 
開發者ID:acgx,項目名稱:ooi3,代碼行數:22,代碼來源:frontend.py

示例10: poi

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_template [as 別名]
def poi(self, request):
        """適配poi中進行遊戲的頁麵,顯示FLASH。該頁麵會檢查會話中是否有api_token、api_starttime和world_ip三個參數,缺少其中任意一個
        都不能進行遊戲,跳轉回登錄頁麵。

        :param request: aiohttp.web.Request
        :return: aiohttp.web.Response or aiohttp.web.HTTPFound
        """
        session = yield from get_session(request)
        token = session.get('api_token', None)
        starttime = session.get('api_starttime', None)
        world_ip = session.get('world_ip', None)
        if token and starttime and world_ip:
            context = {'scheme': request.scheme,
                       'host': request.host,
                       'token': token,
                       'starttime': starttime}
            return aiohttp_jinja2.render_template('poi.html', request, context)
        else:
            self.clear_session(session)
            return aiohttp.web.HTTPFound('/') 
開發者ID:acgx,項目名稱:ooi3,代碼行數:22,代碼來源:frontend.py

示例11: reset_password_allowed

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_template [as 別名]
def reset_password_allowed(request, confirmation):
    db = cfg.STORAGE
    form = await forms.get('ResetPassword').init(request)
    user = await db.get_user({'id': confirmation['user_id']})
    assert user

    while request.method == 'POST' and form.validate():
        await db.update_user(
            user, {'password': encrypt_password(form.password.data)})
        await db.delete_confirmation(confirmation)
        await authorize_user(request, user)
        flash.success(request, cfg.MSG_PASSWORD_CHANGED)
        flash.success(request, cfg.MSG_LOGGED_IN)
        return redirect(cfg.LOGIN_REDIRECT)

    return render_template(themed('reset_password_allowed.html'), request, {
        'auth': {
            'url_for': url_for,
            'cfg': cfg,
            'form': form,
        }
    }) 
開發者ID:imbolc,項目名稱:aiohttp-login,代碼行數:24,代碼來源:handlers.py

示例12: change_password

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_template [as 別名]
def change_password(request):
    db = cfg.STORAGE
    user = request[cfg.REQUEST_USER_KEY]
    form = await forms.get('ChangePassword').init(request)

    while request.method == 'POST' and form.validate():
        if not check_password(form.cur_password.data, user['password']):
            form.cur_password.errors.append(cfg.MSG_WRONG_PASSWORD)
            break

        password = encrypt_password(form.new_password.data)
        await db.update_user(user, {'password': password})

        flash.success(request, cfg.MSG_PASSWORD_CHANGED)
        return redirect(request.path)

    return render_template(themed('change_password.html'), request, {
        'auth': {
            'cfg': cfg,
            'form': form,
            'url_for': url_for,
        }
    }) 
開發者ID:imbolc,項目名稱:aiohttp-login,代碼行數:25,代碼來源:handlers.py

示例13: handler

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_template [as 別名]
def handler(request):
    await asyncio.sleep(0.01)
    session = request.app['session']

    resp = await session.get(service_b_api)
    data_b = await resp.json()

    resp = await session.get(service_e_api)
    data_e = await resp.json()

    tree = {
        'name': 'service_a',
        'host': host,
        'port': port,
        'children': [data_b, data_e],
    }
    ctx = {'zipkin': zipkin_ui_address, 'service': tree}
    return aiohttp_jinja2.render_template('index.html', request, ctx) 
開發者ID:aio-libs,項目名稱:aiozipkin,代碼行數:20,代碼來源:service_a.py

示例14: landing

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_template [as 別名]
def landing(self, request):
        access = await self.auth_svc.get_permissions(request)
        if not access:
            return render_template('login.html', request, dict())
        plugins = await self.data_svc.locate('plugins', {'access': tuple(access), **dict(enabled=True)})
        data = dict(plugins=[p.display for p in plugins], errors=self.app_svc.errors + self._request_errors(request), version=self.app_svc.version)
        return render_template('%s.html' % access[0].name, request, data) 
開發者ID:mitre,項目名稱:caldera,代碼行數:9,代碼來源:rest_api.py

示例15: index_page

# 需要導入模塊: import aiohttp_jinja2 [as 別名]
# 或者: from aiohttp_jinja2 import render_template [as 別名]
def index_page(self, request):
        t = self._template
        context = {'name': self._name}
        return render_template(t, request, context, app_key=TEMPLATE_APP_KEY) 
開發者ID:aio-libs,項目名稱:aiohttp_admin,代碼行數:6,代碼來源:admin.py


注:本文中的aiohttp_jinja2.render_template方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。