如何在Django单元中呈现templaterresponse

2024-09-27 19:15:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试通过执行以下操作来检查Django unittest中的响应主体是否有特定文本:

response = client.post('/path/to/form', form_data)
self.assertTrue('some text' in unicode(response, 'utf-8', 'ignore'))

但是,我得到了一个错误:

^{pr2}$

如果我将unicode()替换为str(),它可以正常工作,但这会阻止我查找Unicode文本。为什么templaterresponse不能像str那样转换成unicode?在


Tags: topathdjango文本selfformclientdata

热门问题