前台表单:

{% csrf_token %}

后台函数:

from django.shortcuts import render,HttpResponse
import json
class Blog():
    def login_in(req):
        if req.method == 'POST':
            data = json.loads(req.body)
            if data['user'] == "admin" and  data['pwd'] == "123":
                return HttpResponse(json.dumps(data), content_type='application/json')
        return render(req, 'error.html')

Python Ajax请求及返回 json_第1张图片