django - 向 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:这现在是一个个人项目,只是为了好玩,所以这解释了我的文档字符串(这就是我认为“”“”“”被称为)
解决方案
推荐阅读
- java - 通过 Java 代码实现测试自动化的大型机访问
- javascript - 从 ng-repeat 列表中删除特殊字符(从 CSV 解析)
- scheme - 有没有办法在列表中没有列表的情况下进行打印?
- python - 如何在微服务中存储版本化的 XSLT 文件
- c - malloc() 是否在循环中重用相同的内存地址?
- unit-testing - 使用 pytest 测试 Flask 应用程序时找不到 404
- javascript - 如何在 JavaScript 中使用 KD-Tree 比较 2 个数据集?
- javascript - 是否可以在输入字段中显示反应组件?
- c# - C# WPF - 使用 VS2019 安装向导为计算机上的每个用户使用本地数据库 sqlite 部署应用程序
- ios - Xamarin.iOS 中的 OneSignal - 屏幕锁定时没有通知声音