Django视图测试 [英] Django view testing
本文介绍了Django视图测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找出是否有一种快速的方法可以通过python或django shell测试我的django视图功能。我将如何实例化并传递仿造的HTTPrequest对象?
I'm trying to figure out if there is a quick way to test my django view functions form either the python or django shell. How would I go about instantiating and passing in faux HTTPrequest object?
推荐答案
django.test.client
是必经之路。
来自 django docs
from django.test.client import Client
c = Client()
response = c.post('/login/', {'username': 'john', 'password': 'smith'})
response.status_code
这篇关于Django视图测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文