我正在为post视图写一个测试。它确实有效,但是当我尝试用APIClient.post发布到它时,我得到了QueryDict:{}。下面是一个测试:
class SMSCreateData(APITestCase):
...
def test_SMS(self):
...
postData = {'Body': string, 'From': phNum.phone_number}
self.client.post(reverse('SMS-data'), postData)下面是这样的观点:
def SMSSubmitDataPointView(request):
...
try:
print request.POST
...发布于 2018-05-08 19:23:08
urlencode post数据,并将content_type设置为application/x-www-form-urlencoded。
from urllib.parse import urlencode
# In python 2, use this instead: from urllib import urlencode
response = self.client.post(reverse('SMS-data'), urlencode(postData),
content_type='application/x-www-form-urlencoded'
)您将在request.POST中获得数据
https://stackoverflow.com/questions/50240315
复制相似问题