python - Django TypeError:force_authenticate()缺少1个必需的位置参数:'self'
问题描述
测试用例setUp()首先创建一个用户并尝试强制对用户进行身份验证,但发生有线错误......
类型错误:force_authenticate() 缺少 1 个必需的位置参数:'self'
class PrivateUserApiTest(TestCase):
""" Test API that require authentication """
def setUp(self):
self.user = create_user(
email="test@test.com",
password="testpass",
name="testName"
)
print(self.user)
self.client = APIClient
self.client.force_authenticate(user=self.user) # <--
解决方案
如前所述@BhavyaParikh
,而不是这样:
self.client = APIClient
做这个:
self.client = APIClient()
推荐阅读
- mysql - 在 bash 流中压缩文件时保留文件名
- java - Firestore SetOptions.mergeFields 不起作用
- r - R包“igraph”安装出错
- arrays - 在特定范围之间将一行中的所有单元格向右(和向左)移动 1 个单元格
- jquery - 如何使用 jquery 选项卡重定向到另一个网页?
- xml - 在 Odoo 10 中按上下文/域过滤
- php - 在没有英文网络系统(PHP / Mysql)中避免编码/整理字符错误的最佳方法?
- azure - 我可以从 Azure Data Lake U-SQL 中的 CSV 文件中检索有限的数据集吗?
- sql - 列数据类型的条件转换
- python - microsoft graph api 不会将 onenote 页面的创建日期转换为本地日期