已解决,与视频不同,需要用json.dumps将dict转化为str
import json
class UserAskView(View):
def post(self, request):
userask_form = UserAskModelForm(request.POST)
if not userask_form.is_valid():
json_dict={'status':'fail','msg':'填写信息不正确'}
return HttpResponse(json.dumps(json_dict), content_type="application/json")
json_dict = {'status': 'success'}
return HttpResponse(json.dumps(json_dict), content_type="application/json")