首页 > 解决方案 > 向 Django 请求添加令牌

问题描述

谁能帮我在我的请求中添加一个 api AUTH 令牌,我不确定如何将非 Django AUTH 令牌添加到请求中,我希望能够在每次使用网站时将 AUTH 令牌插入到我的请求中不必不断响应 api 让我做的 SMS 消息。这是我到目前为止的代码

from robin_stocks import robinhood as RH

@login_required
def home(request: HttpRequest, *args, **kwargs):
    """
    The landing page for the user, after they log in should contain a bunch of deets
    """
    if (request.COOKIES['ul.token']):
        positions = RH.account.get_all_positions()
        print(positions)
    else:
        token = RH.authentication.login(username=env.RHemail, password = env.RHpassword)
        request.COOKIES['ul.token'] = token.access_token

    context = {'positions' : positions}
    return render(request, 'home.html', context)

我将它保存为 ul.token 因为当我登录我的 robin hood 帐户时,这就是我的 cookie 中的令牌名称。我可能也错过了这个标记 PS:这现在是一个个人项目,只是为了好玩,所以这解释了我的文档字符串(这就是我认为“”“”“”被称为)

标签: djangoapitoken

解决方案


推荐阅读