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


Python response.html方法代码示例

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


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

示例1: test_redirect_without_url

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def test_redirect_without_url(app):
    sanic_app, sanic_jwt = app

    @sanic_app.route("/index.html")
    def index(request):
        return html("<html><body>Home</body></html>")

    @sanic_app.route("/protected/static")
    @sanic_jwt.protected(redirect_on_fail=True)
    async def my_protected_static(request):
        return text("", status=200)

    request, response = sanic_app.test_client.get("/protected/static")

    assert response.status == 200
    assert response.body == b'<html><body>Home</body></html>'
    assert response.history
    assert response.history[0].status_code == 302 
开发者ID:ahopkins,项目名称:sanic-jwt,代码行数:20,代码来源:test_decorators.py

示例2: hello_world

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def hello_world(request):
    '''
        Since the path '/' does not match the regular expression r'/api/*',
        this route does not have CORS headers set.
    '''
    return html('''
<html>
    <head></head>
    <body>
    <h1>Hello CORS!</h1>
    <h3> End to end editable example with jquery! </h3>
    <a class="jsbin-embed" href="http://jsbin.com/zazitas/embed?js,console">JS Bin on jsbin.com</a>
    <script src="//static.jsbin.com/js/embed.min.js?3.35.12"></script>
    </body>
</html>
''') 
开发者ID:ashleysommer,项目名称:sanic-cors,代码行数:18,代码来源:app_based_example.py

示例3: get_exception

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def get_exception(request):
    '''
        Since the path matches the regular expression r'/api/*', this resource
        automatically has CORS headers set.

        Browsers will first make a preflight request to verify that the resource
        allows cross-origin POSTs with a JSON Content-Type, which can be simulated
        as:
        $ curl --include -X OPTIONS http://127.0.0.1:5000/exception \
            --header Access-Control-Request-Method:POST \
            --header Access-Control-Request-Headers:Content-Type \
            --header Origin:www.examplesite.com
        >> HTTP/1.0 200 OK
        Content-Type: text/html; charset=utf-8
        Allow: POST, OPTIONS
        Access-Control-Allow-Origin: *
        Access-Control-Allow-Headers: Content-Type
        Access-Control-Allow-Methods: DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT
        Content-Length: 0
        Server: Werkzeug/0.9.6 Python/2.7.9
        Date: Sat, 31 Jan 2015 22:25:22 GMT
    '''
    raise Exception("example") 
开发者ID:ashleysommer,项目名称:sanic-cors,代码行数:25,代码来源:app_based_example.py

示例4: __init__

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def __init__(self, app, app_type=None, config_path=None, config_url=None,
                 url_prefix='/api/doc', title='API doc', editor=False):

        self._app = app
        self._title = title
        self._url_prefix = url_prefix.rstrip('/')
        self._config_url = config_url
        self._config_path = config_path
        self._editor = editor

        assert self._config_url or self._config_path, 'config_url or config_path is required!'

        self._env = Environment(
            loader=FileSystemLoader(str(CURRENT_DIR.joinpath('templates'))),
            autoescape=select_autoescape(['html'])
        )

        if app_type and hasattr(self, '_{}_handler'.format(app_type)):
            getattr(self, '_{}_handler'.format(app_type))()
        else:
            self._auto_match_handler() 
开发者ID:PWZER,项目名称:swagger-ui-py,代码行数:23,代码来源:core.py

示例5: _aiohttp_handler

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def _aiohttp_handler(self):
        from aiohttp import web

        async def swagger_doc_handler(request):
            return web.Response(text=self.doc_html, content_type='text/html')

        async def swagger_editor_handler(request):
            return web.Response(text=self.editor_html, content_type='text/html')

        async def swagger_config_handler(request):
            return web.json_response(self.get_config(request.host))

        self._app.router.add_get(self._uri(), swagger_doc_handler)
        self._app.router.add_get(self._uri('/'), swagger_doc_handler)

        if self._editor:
            self._app.router.add_get(self._uri('/editor'), swagger_editor_handler)

        self._app.router.add_get(self._uri('/swagger.json'), swagger_config_handler)
        self._app.router.add_static(self._uri('/'), path='{}/'.format(self.static_dir)) 
开发者ID:PWZER,项目名称:swagger-ui-py,代码行数:22,代码来源:core.py

示例6: _sanic_handler

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def _sanic_handler(self):
        from sanic import response
        from sanic.blueprints import Blueprint

        swagger_blueprint = Blueprint('swagger_blueprint', url_prefix=self._url_prefix)

        @swagger_blueprint.get('/')
        async def swagger_blueprint_doc_handler(request):
            return response.html(self.doc_html)

        if self._editor:
            @swagger_blueprint.get('/editor')
            async def swagger_blueprint_editor_handler(request):
                return response.html(self.editor_html)

        @swagger_blueprint.get('/swagger.json')
        async def swagger_blueprint_config_handler(request):
            return response.json(self.get_config(request.host))

        swagger_blueprint.static('/', str(self.static_dir))
        self._app.blueprint(swagger_blueprint) 
开发者ID:PWZER,项目名称:swagger-ui-py,代码行数:23,代码来源:core.py

示例7: apiui_command_help

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def apiui_command_help(request, user):
    template = env.get_template('apiui_command_help.html')
    if len(request.query_args) != 0:
        data = urllib.parse.unquote(request.query_args[0][1])
        query = await db_model.payloadtype_query()
        try:
            payloadtype = await db_objects.get(query, ptype=data)
        except Exception as e:
            data = ""
    else:
        data = ""
    if use_ssl:
        content = template.render(links=await respect_pivot(links, request), name=user['username'], http="https",
                                  ws="wss", config=user['ui_config'], view_utc_time=user['view_utc_time'], agent=data)
    else:
        content = template.render(links=await respect_pivot(links, request), name=user['username'], http="http",
                                  ws="ws", config=user['ui_config'], view_utc_time=user['view_utc_time'], agent=data)
    return response.html(content)

# add links to the routes in this file at the bottom 
开发者ID:its-a-feature,项目名称:Apfell,代码行数:22,代码来源:api_routes.py

示例8: settings

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def settings(request, user):
    template = env.get_template('settings.html')
    try:
        query = await db_model.operator_query()
        operator = await db_objects.get(query, username=user['username'])
        op_json = operator.to_json()
        del op_json['ui_config']
        if use_ssl:
            content = template.render(links=await respect_pivot(links, request), name=user['username'], http="https", ws="wss",
                                      op=op_json, config=user['ui_config'], view_utc_time=user['view_utc_time'])
        else:
            content = template.render(links=await respect_pivot(links, request), name=user['username'], http="http", ws="ws",
                                      op=op_json, config=user['ui_config'], view_utc_time=user['view_utc_time'])
        return response.html(content)
    except Exception as e:
        print(e)
        return json({'status': 'error', 'error': 'Failed to find operator'}) 
开发者ID:its-a-feature,项目名称:Apfell,代码行数:19,代码来源:routes.py

示例9: test_same_origin_jupyter_display

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def test_same_origin_jupyter_display(driver, driver_wait, mount, server_url):
    clicked = idom.Var(False)

    @idom.element
    async def SimpleButton(self):
        @idom.event
        async def on_click(event):
            clicked.set(True)

        return idom.html.button(
            {"id": "simple-button", "onClick": on_click}, "click me same origin"
        )

    mount(SimpleButton)
    driver.get(f"{server_url}/__test_jupyter_widget_client__")

    client_button = driver.find_element_by_id("simple-button")
    client_button.click()

    driver_wait.until(lambda d: clicked.get()) 
开发者ID:rmorshea,项目名称:idom,代码行数:22,代码来源:test_jupyter.py

示例10: add_session_to_request

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def add_session_to_request(request):
    # before each request initialize a session
    # using the client's request
    host = request.headers.get('host', None)
    user_agent = request.headers.get('user-agent', None)
    if user_agent:
        user_ip = request.headers.get('X-Forwarded-For')
        LOGGER.info('user ip is: {}'.format(user_ip))
        if user_ip in CONFIG.FORBIDDEN:
            return html("<h3>网站正在维护...</h3>")
        if CONFIG.VAL_HOST == 'true':
            if not host or host not in CONFIG.HOST:
                return redirect('http://www.owllook.net')
        if CONFIG.WEBSITE['IS_RUNNING']:
            await app.session_interface.open(request)
        else:
            return html("<h3>网站正在维护...</h3>")
    else:
        return html("<h3>网站正在维护...</h3>") 
开发者ID:howie6879,项目名称:owllook,代码行数:21,代码来源:server.py

示例11: chapter

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def chapter(request):
    """
    返回小说章节目录页
    : content_url   这决定当前U页面url的生成方式
    : url           章节目录页源url
    : novels_name   小说名称
    :return: 小说章节内容页
    """
    url = request.args.get('url', None)
    novels_name = request.args.get('novels_name', None)
    netloc = get_netloc(url)
    if netloc not in RULES.keys():
        return redirect(url)
    if netloc in REPLACE_RULES.keys():
        url = url.replace(REPLACE_RULES[netloc]['old'], REPLACE_RULES[netloc]['new'])
    content_url = RULES[netloc].content_url
    content = await cache_owllook_novels_chapter(url=url, netloc=netloc)
    if content:
        content = str(content).strip('[],, Jjs').replace(', ', '').replace('onerror', '').replace('js', '').replace(
            '加入书架', '')
        return template(
            'chapter.html', novels_name=novels_name, url=url, content_url=content_url, soup=content)
    else:
        return text('解析失败,请将失败页面反馈给本站,请重新刷新一次,或者访问源网页:{url}'.format(url=url)) 
开发者ID:howie6879,项目名称:owllook,代码行数:26,代码来源:novels_blueprint.py

示例12: owllook_register

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def owllook_register(request):
    """
    用户登录
    :param request:
    :return:
        :   -1  用户名或密码不能为空
        :   0   用户名或密码错误
        :   1   登陆成功
    """
    user = request['session'].get('user', None)
    if user:
        return redirect('/')
    else:
        ver_que_ans = ver_question()
        if ver_que_ans:
            request['session']['index'] = ver_que_ans
            return template(
                'register.html',
                title='owllook - 注册 - 网络小说搜索引擎',
                question=ver_que_ans[1]
            )
        else:
            return redirect('/') 
开发者ID:howie6879,项目名称:owllook,代码行数:25,代码来源:novels_blueprint.py

示例13: test_html

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def test_html(app):
    class Foo:
        def __html__(self):
            return "<h1>Foo</h1>"

        def _repr_html_(self):
            return "<h1>Foo object repr</h1>"

    class Bar:
        def _repr_html_(self):
            return "<h1>Bar object repr</h1>"

    @app.route("/")
    async def handler(request):
        return html("<h1>Hello</h1>")

    @app.route("/foo")
    async def handler(request):
        return html(Foo())

    @app.route("/bar")
    async def handler(request):
        return html(Bar())

    request, response = app.test_client.get("/")
    assert response.content_type == "text/html; charset=utf-8"
    assert response.text == "<h1>Hello</h1>"

    request, response = app.test_client.get("/foo")
    assert response.text == "<h1>Foo</h1>"

    request, response = app.test_client.get("/bar")
    assert response.text == "<h1>Bar object repr</h1>" 
开发者ID:huge-success,项目名称:sanic,代码行数:35,代码来源:test_requests.py

示例14: short_chain

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def short_chain(request: Request, short_chain: str):
    """
    短链接进入App详情
    :param request:
    :param short_chain: 短链接
    :return:
    """
    session = Session()
    query = DB.model_exists(session, AppModel, short_chain_uri_=short_chain)
    if not query:
        raise BadRequest('not find short chain: {}'.format(short_chain))
    model = query.one()
    url = '{}/#/app/{}'.format(Config.url, model.id)
    # return redirect('/#/app/{}'.format(model.id))
    return html('''
<html>
    <header>
    </header>

    <body style="padding: 30px">
        <div>跳转中...</div>
        <a href='{0}'>如果没有打开请点击这里</a>
    </body>

    <script>
        setTimeout("location.href='{0}'", 2000);
    </script>
</html>
    '''.format(url)) 
开发者ID:skytoup,项目名称:AppServer,代码行数:31,代码来源:short_chain.py

示例15: render_graphiql

# 需要导入模块: from sanic import response [as 别名]
# 或者: from sanic.response import html [as 别名]
def render_graphiql(
    jinja_env=None,
    graphiql_version=None,
    graphiql_template=None,
    params=None,
    result=None,
):
    graphiql_version = graphiql_version or GRAPHIQL_VERSION
    template = graphiql_template or TEMPLATE
    template_vars = {
        "graphiql_version": graphiql_version,
        "query": params and params.query,
        "variables": params and params.variables,
        "operation_name": params and params.operation_name,
        "result": result,
    }

    if jinja_env:
        template = jinja_env.from_string(template)
        if jinja_env.is_async:
            source = await template.render_async(**template_vars)
        else:
            source = template.render(**template_vars)
    else:
        source = simple_renderer(template, **template_vars)

    return html(source) 
开发者ID:graphql-python,项目名称:graphql-server-core,代码行数:29,代码来源:render_graphiql.py


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