传递请求时,重定向响应返回对象而不是重定向

问题描述

所以我在 FastAPI 中有这个小项目,它实际上是一个代码,如果用户登录,它会将用户重定向登录页面

问题是它在请求时成功重定向:请求未通过。当我传递它们时,它不会重定向,而是返回 RedirectResponse 对象。我在处理 HTML 时需要请求。

def loginrequired(token: str = Depends(oauth2_scheme)):
    
    credentials_exception = RedirectResponse(url='/login')
    credentials_exception.delete_cookie(key="access_token")
    
    if token =='REDIRECT':

        return credentials_exception
    try:
        payload = jwt.decode(token,SECRET_KEY,algorithms=[ALGORITHM])
        username: str = payload.get("sub")
        if username is None:

            return credentials_exception
        token_data = TokenData(username=username)
    except JWTError:
        return credentials_exception
        
    user = USER.getUserDetails(username=token_data.username) | {'token':token}
    
    if user is None:
        return credentials_exception
    return user

@app.get("/profile")
def DashBoard( request:Request,current_user : User =Depends(loginrequired)):
    data= current_user

    summary={'total':0,'average':0,'withdrawn':0}
    return data

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...