lets do this.
This is your dictionary in javascript:
var data = {"name":"nitin raturi"};
Now define a function that will make a post request using jquery.
function send_data(data, callback) {
// callback is a function that you should pass to handle your response
$.ajax({
type: "POST",
url: '/sample-url/', // change this to your url here
data: {"data": JSON.stringify(data)},
success: function (response) {
callback(response);
},
});
}
Now use the send_data function like this:
send_data(data,function(response){
//handle your response here
console.log(response);
})
Now you can access your data in your django view like this:
import json
@csrf_exempt
def my_view(request):
data = request.POST.get('data')
data = json.loads(data) # this will convert your json data to python dictionary
name = data.get("name")
// Handle your data and return anything you wish
return render(request,"index.html",{})