python Django:测试中的ajax json视图

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Django:测试中的ajax json视图相关的知识,希望对你有一定的参考价值。

import json
from django.test import TestCase

class JSONViewTestCase(TestCase):

    def test_json_view(self):
        response = self.client.post(
            reverse('my_json_view'),
            json.dumps({
                # your JSON
            }),
            'json',
            HTTP_X_REQUESTED_WITH='XMLHttpRequest',
        )
        json_string = response.content
        response_data = json.loads(json_string)
        # do smth.

以上是关于python Django:测试中的ajax json视图的主要内容,如果未能解决你的问题,请参考以下文章