所以我有这段代码:
request = self.factory.get(reverse('portal-edit-automation', args=(self.rule.id,)))
response = EditAutomation.as_view()(request)
如果我在它之前设置一个pdb断点并执行:
(Pdb) reverse('portal-edit-automation', args=(self.rule.id,))
u'/portal/automations/edit/1/'
我得到了预期的回复。
那么为什么我在运行测试套件时会得到这个呢?
AttributeError: Generic detail view EditAutomation must be called with either an object pk or a slug.
答案 0 :(得分:3)
您必须使用请求和主键调用视图,例如:
std::sort(std::begin(g1), std::end(g1));