How to use the sanic.response.redirect function in sanic

To help you get started, we’ve selected a few sanic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyx / sanic-auth / tests / test_auth.py View on Github external
async def logout(request):
        auth.logout_user(request)
        return response.redirect('/user')
github howie6879 / owllook / owllook / server.py View on Github external
async 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>")
github mxpv / podsync / cmd / resolver / server.py View on Github external
async def download(req, feed_id, video_id):
    if req.method == 'HEAD':
        return response.text('')

    try:
        redirect_url = resolver.download(feed_id, video_id)
        return response.redirect(redirect_url)
    except resolver.InvalidUsage:
        raise InvalidUsage()
    except resolver.QuotaExceeded:
        raise ServerError('Too many requests. Daily limit is 1000. Consider upgrading account to get unlimited access.',
                          status_code=429)
github zhao94254 / fun / pweb / concurrency / tsanic.py View on Github external
async def test_redirect(request):
    return response.redirect(app.url_for('index'))
github its-a-feature / Apfell / apfell-docker / app / routes / routes.py View on Github external
async def logout(request, user):
    resp = response.redirect("/login")
    del resp.cookies['access_token']
    del resp.cookies['refresh_token']
    # now actually invalidate tokens
    await invalidate_refresh_token(user['id'])
    return resp
github omarryhan / aiogoogle / examples / auth(production_unsafe) / oauth2.py View on Github external
def authorize(request):
    if aiogoogle.oauth2.is_ready(CLIENT_CREDS):
        uri = aiogoogle.oauth2.authorization_url(
            client_creds=CLIENT_CREDS,
            state=state,
            access_type="offline",
            include_granted_scopes=True,
            login_hint=EMAIL,
            prompt="select_account",
        )
        # Step A
        return response.redirect(uri)
    else:
        raise ServerError("Client doesn't have enough info for Oauth2")
github huge-success / sanic / examples / url_for_example.py View on Github external
async 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)
github howie6879 / owllook / owllook / views / md_blueprint.py View on Github external
'都市',
        '职场',
        '军事',
        '历史',
        '游戏',
        '体育',
        '科幻',
        '灵异',
        '二次元',
    ]
    if novels_type in first_type:
        novels_head = [novels_type]
    elif novels_type == first_type_title:
        novels_head = ['#']
    else:
        return redirect('qidian')
    search_ranking = await cache_others_search_ranking(spider='qidian', novel_type=novels_type)
    title = "owllook - 起点小说榜单"
    if user:
        return template('index.html',
                        title=title,
                        is_login=1,
                        is_qidian=1,
                        is_qidian_model=1,
                        user=user,
                        search_ranking=search_ranking,
                        first_type=first_type,
                        first_type_title=first_type_title,
                        novels_head=novels_head)
    else:
        return template('index.html',
                        title=title,
github rmorshea / idom / idom / server / sanic.py View on Github external
def redirect_to_index(request: request.Request) -> response.HTTPResponse:
                return response.redirect(
                    request.app.url_for(handler_name(client_files), path="index.html")
                )
github howie6879 / hproxy / hproxy / server.py View on Github external
async def check_request(request):
    if CONFIG.VAL_HOST == '1':
        host = request.headers.get('host', None)
        if not host or host not in CONFIG.HOST:
            return redirect('http://www.baidu.com')