1👍
✅
views.py
# data should be a list of dictionaries and not a queryset
return HttpResponse(json.dumps(data), content_type="application/json")
livestream/main.html
$.ajax({
success: function(data) {
console.log(data); // here is your server response
}
});
0👍
Just change your view to return JSON:
import json
from django.http import HttpResponse
@csrf_exempt
def postdata(request):
r = requests.post(url ,headers=headers, auth=auth, data=json.dumps(data))
return HttpResponse(json.dumps(r, ensure_ascii=False),
content_type='application/json')
Then use that JSON to do whatever you need on the client-side.
- [Answer]-How to clean username with Django allauth adapter?
- [Answer]-Issues with page processors in Mezzanine
- [Answer]-Why isn't my form submitting?
Source:stackexchange.com