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


Python response.redirect方法代碼示例

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


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

示例1: test_redirect_with_params

# 需要導入模塊: from sanic import response [as 別名]
# 或者: from sanic.response import redirect [as 別名]
def test_redirect_with_params(app, test_str):
    use_in_uri = quote(test_str)

    @app.route("/api/v1/test/<test>/")
    async def init_handler(request, test):
        return redirect(f"/api/v2/test/{use_in_uri}/")

    @app.route("/api/v2/test/<test>/")
    async def target_handler(request, test):
        assert test == test_str
        return text("OK")

    _, response = app.test_client.get(f"/api/v1/test/{use_in_uri}/")
    assert response.status == 200

    assert response.content == b"OK" 
開發者ID:huge-success,項目名稱:sanic,代碼行數:18,代碼來源:test_redirect.py

示例2: redirect_login_record_session_google

# 需要導入模塊: from sanic import response [as 別名]
# 或者: from sanic.response import redirect [as 別名]
def redirect_login_record_session_google(request):
    success_cb, error_cb, adapter, first_response = oauth_init(request)

    if adapter is None:
        return first_response

    authomatic = Authomatic(config=CONFIG, secret=SECRET_SALT)

    result = authomatic.login(adapter, 'google',
                              # session=session['authomatic'],
                              session_saver=lambda: None)
    if result:
        if result.error:
            warning("Google login error", result.error)
            return response.redirect('%s?error=%s' % (error_cb, result.error))
        elif result.user:
            debug("Google login success", result.user)
            result.user.update()
            debug("Google login update success", result.user)
            userdict = result.user.to_dict()
            return upsert_login_redirect(request, "google:" + userdict['email'], result.user.to_dict(), success_cb, adapter)
    return adapter.response 
開發者ID:bloomsburyai,項目名稱:cape-webservices,代碼行數:24,代碼來源:google_login.py

示例3: reroute_to_refresh

# 需要導入模塊: from sanic import response [as 別名]
# 或者: from sanic.response import redirect [as 別名]
def reroute_to_refresh(request, resp):
    resp.headers['Server'] = server_header
    # if you browse somewhere and get greeted with response.json.get('reasons')[0] and "Signature has expired"
    if resp and (resp.status == 403 or resp.status == 401) and resp.content_type == "application/json":
        output = js.loads(resp.body)
        if 'reasons' in output and 'Signature has expired' in output['reasons'][0]:
            # unauthorized due to signature expiring, not invalid auth, redirect to /refresh
            if request.cookies['refresh_token'] and request.cookies['access_token']:
                # auto generate a new
                return response.redirect("/uirefresh")
        if 'exception' in output and output['exception'] == "AuthenticationFailed":
            # authentication failed for one reason or another, redirect them to login
            resp = response.redirect("/login")
            del resp.cookies['access_token']
            del resp.cookies['refresh_token']
            return resp 
開發者ID:its-a-feature,項目名稱:Apfell,代碼行數:18,代碼來源:routes.py

示例4: add_session_to_request

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

示例5: admin_setting

# 需要導入模塊: from sanic import response [as 別名]
# 或者: from sanic.response import redirect [as 別名]
def admin_setting(request):
    user = request['session'].get('user', None)
    if user:
        try:
            motor_db = motor_base.get_db()
            data = await motor_db.user.find_one({'user': user})
            if data:
                return template('admin_setting.html', title='{user}的設置 - owllook'.format(user=user),
                                is_login=1,
                                user=user,
                                register_time=data['register_time'],
                                email=data.get('email', '請盡快綁定郵箱'))
            else:
                return text('未知錯誤')
        except Exception as e:
            LOGGER.error(e)
            return redirect('/')
    else:
        return redirect('/') 
開發者ID:howie6879,項目名稱:owllook,代碼行數:21,代碼來源:md_blueprint.py

示例6: chapter

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

示例7: owllook_register

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

示例8: index

# 需要導入模塊: from sanic import response [as 別名]
# 或者: from sanic.response import redirect [as 別名]
def index(request):
    # generate a URL for the endpoint `post_handler`
    url = app.url_for('post_handler', post_id=5)
    # the URL is `/posts/5`, redirect to it
    return response.redirect(url) 
開發者ID:huge-success,項目名稱:sanic,代碼行數:7,代碼來源:url_for_example.py

示例9: handle_request

# 需要導入模塊: from sanic import response [as 別名]
# 或者: from sanic.response import redirect [as 別名]
def handle_request(request):
    return response.redirect('/redirect') 
開發者ID:huge-success,項目名稱:sanic,代碼行數:4,代碼來源:redirect_example.py

示例10: handler

# 需要導入模塊: from sanic import response [as 別名]
# 或者: from sanic.response import redirect [as 別名]
def handler(request):
    return response.redirect("/sleep/3") 
開發者ID:huge-success,項目名稱:sanic,代碼行數:4,代碼來源:delayed_response.py

示例11: redirect_app

# 需要導入模塊: from sanic import response [as 別名]
# 或者: from sanic.response import redirect [as 別名]
def redirect_app(app):
    @app.route("/redirect_init")
    async def redirect_init(request):
        return redirect("/redirect_target")

    @app.route("/redirect_init_with_301")
    async def redirect_init_with_301(request):
        return redirect("/redirect_target", status=301)

    @app.route("/redirect_target")
    async def redirect_target(request):
        return text("OK")

    @app.route("/1")
    def handler1(request):
        return redirect("/2")

    @app.route("/2")
    def handler2(request):
        return redirect("/3")

    @app.route("/3")
    def handler3(request):
        return text("OK")

    @app.route("/redirect_with_header_injection")
    async def redirect_with_header_injection(request):
        return redirect("/unsafe\ntest-header: test-value\n\ntest-body")

    return app 
開發者ID:huge-success,項目名稱:sanic,代碼行數:32,代碼來源:test_redirect.py

示例12: index

# 需要導入模塊: from sanic import response [as 別名]
# 或者: from sanic.response import redirect [as 別名]
def index(request: Request):
    return redirect('/index.html')

# 允許跨域
# @app.middleware('response')
# async def access_control_all_origin(request: Request, response):
#     response.headers['Access-Control-Allow-Origin'] = '*' 
開發者ID:skytoup,項目名稱:AppServer,代碼行數:9,代碼來源:__init__.py

示例13: index

# 需要導入模塊: from sanic import response [as 別名]
# 或者: from sanic.response import redirect [as 別名]
def index(request):
    return redirect("{}/".format(swagger_blueprint.url_prefix)) 
開發者ID:huge-success,項目名稱:sanic-openapi,代碼行數:4,代碼來源:swagger.py

示例14: force_https

# 需要導入模塊: from sanic import response [as 別名]
# 或者: from sanic.response import redirect [as 別名]
def force_https(request):
    if DEBUG:
        return None

    host = request.headers.get("Host", "")
    protocol = "https" if request.transport.get_extra_info("sslcontext") else "http"

    if request.headers.get("x-forwarded-proto", protocol) == "http":
        args = ("https", host, request.path, None, request.query_string, None)
        url = urlunparse(args)
        return redirect(url) 
開發者ID:okfn-brasil,項目名稱:vitimas-da-intolerancia,代碼行數:13,代碼來源:__init__.py

示例15: upsert_login_redirect

# 需要導入模塊: from sanic import response [as 別名]
# 或者: from sanic.response import redirect [as 別名]
def upsert_login_redirect(request, user_id: str, third_party_info: dict, success_cb: str, adapter):
    debug('Login', user_id, 'with', third_party_info, success_cb)
    user_or_none: User = User.get('user_id', user_id)
    if user_or_none is None:
        user_or_none = create_user(user_id=user_id, password=str(token_urlsafe()), third_party_info=third_party_info)
    session_obj: Session = Session.create(user_id=user_or_none.user_id)
    request['session_id'] = session_obj.session_id
    return redirect(success_cb) 
開發者ID:bloomsburyai,項目名稱:cape-webservices,代碼行數:10,代碼來源:third_party_login_core.py


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