在 Django testing documentation他们 promise 您可以“测试是否为给定的 URL 执行了正确的 View ”。
但是我没有发现如何测试执行哪个 View 的任何可能性。我希望在 Response
class但没有关于执行 View 的任何内容。
提前致谢。
最佳答案
您可以这样提取 View 函数名称
from django.test.client import Client
c = Client()
response = c.get('/')
from django.core.urlresolvers import resolve
resolve(response.request["PATH_INFO"])[0].func_name
关于Django 测试 : determine which view was executed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3669345/