How to use the starlette.responses.RedirectResponse function in starlette

To help you get started, we’ve selected a few starlette 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 encode / starlette / tests / test_responses.py View on Github external
async def app(scope, receive, send):
        if scope["path"] == "/":
            response = Response("hello, world", media_type="text/plain")
        else:
            response = RedirectResponse("/")
        await response(scope, receive, send)
github abersheeran / index.py / index / applications.py View on Github external
def get_pathlist(uri: str) -> typing.List[str]:
        if uri.endswith("/index"):
            return RedirectResponse(f'/{uri[:-len("/index")]}', status_code=301)

        if uri.endswith("/"):
            uri += "index"

        filepath = uri[1:].strip(".")
        # Google SEO
        if not config.ALLOW_UNDERLINE:
            if "_" in uri:
                return RedirectResponse(f'/{uri.replace("_", "-")}', status_code=301)
            filepath = filepath.replace("-", "_")

        # judge python file
        abspath = os.path.join(config.path, "views", filepath + ".py")
        if not os.path.exists(abspath):
            raise HTTPException(404)

        pathlist = filepath.split("/")
        pathlist.insert(0, "views")

        return pathlist
github opensight-cv / opensight / opsi / webserver / app.py View on Github external
def trailingslash_redirect(self, request):
        return RedirectResponse(request.url.path + "/")
github accent-starlette / starlette-admin / starlette_admin / admin / base.py View on Github external
if not form.validate():
            context.update({"form": form, "object": instance})
            return config.templates.TemplateResponse(cls.delete_template, context)

        try:
            await cls.do_delete(instance, form, request)
            message(request, "Deleted successfully", "success")
        except IntegrityError:
            message(
                request,
                "Could not be deleted due to being referenced by a related object",
                "error",
            )

        return RedirectResponse(
            url=request.url_for(cls.url_names()["list"]), status_code=302
        )
github drkane / find-that-charity / findthatcharity / apps / randcharity.py View on Github external
active = request.query_params.get("active", False)
    res = es.search(
        index=settings.ES_INDEX,
        doc_type=settings.ES_TYPE,
        size=1,
        body=random_query(active, "Registered Charity"),
        ignore=[404]
    )
    char = None
    if "hits" in res:
        if "hits" in res["hits"]:
            char = res["hits"]["hits"][0]

    if char:
        if filetype == "html":
            return RedirectResponse(request.url_for('orgid_html', orgid=char["_id"]))
    return JSONResponse(char["_source"])
github sage-org / sage-engine / sage / http_server / server.py View on Github external
async def well_known():
        """Alias for /void/"""
        return RedirectResponse(url="/void/")
github rmyers / cannula / examples / cloud / session.py View on Github external
)

    if resp.errors:
        LOG.error(f'{resp.errors}')
        raise Exception('Unable to login user')

    LOG.info(f'Auth Response: {resp.data}')
    token = resp.data['login']
    user = set_user(
        username=token['user']['name'],
        auth_token=token['authToken'],
        catalog=token['catalog'],
        roles=token['roles']
    )

    response = RedirectResponse('/dashboard')
    response.set_cookie(SESSION_COOKE_NAME, user.session_id)
    return response
github abersheeran / index.py / index / applications.py View on Github external
def get_pathlist(uri: str) -> typing.List[str]:
        if uri.endswith("/index"):
            return RedirectResponse(f'/{uri[:-len("/index")]}', status_code=301)

        if uri.endswith("/"):
            uri += "index"

        filepath = uri[1:].strip(".")
        # Google SEO
        if not config.ALLOW_UNDERLINE:
            if "_" in uri:
                return RedirectResponse(f'/{uri.replace("_", "-")}', status_code=301)
            filepath = filepath.replace("-", "_")

        # judge python file
        abspath = os.path.join(config.path, "views", filepath + ".py")
        if not os.path.exists(abspath):
            raise HTTPException(404)