Hi guys,
I need to send a posto to django server, but qhen i do the post a get the following error:
Traceback (most recent call last):
File “C:\Users\goncalo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\core\handlers\exception.py”, line 47, in inner
response = get_response(request)
File “C:\Users\goncalo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\debug_toolbar\middleware.py”, line 67, in call
panel.generate_stats(request, response)
File “C:\Users\goncalo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\debug_toolbar\panels\headers.py”, line 53, in generate_stats
self.response_headers = OrderedDict(sorted(response.items()))
AttributeError: ‘str’ object has no attribute ‘items’
Internal Server Error: /ajax/filter_by_user
Traceback (most recent call last):
File “C:\Users\goncalo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\django\core\handlers\exception.py”, line 47, in inner
response = get_response(request)
File “C:\Users\goncalo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\debug_toolbar\middleware.py”, line 67, in call
panel.generate_stats(request, response)
File “C:\Users\goncalo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\debug_toolbar\panels\headers.py”, line 53, in generate_stats
self.response_headers = OrderedDict(sorted(response.items()))
AttributeError: ‘str’ object has no attribute ‘items’
my js fuction:
var userSelect = $("#userSelect").val();
var areaSelect2 = $("#areaSelect2").val();
var csrftoken = getCookie(“csrftoken”);
header = {'X-CSRFToken': csrftoken,
"Content-Type": "application/json",
}
$.ajax({
type: 'POST',
url: "ajax/filter_by_user",
headers: header,
data :{
"filtro" : "user",
"areas" : areaSelect2,
"users" : userSelect,
"startDate" : startDate,
"endDate" : endDate
},
mode: 'same-origin',
success: function (response) {
console.log(response)
},
error: function (response) {
// alert the error if any error occured
console.log(response);
}
})
in the view i only have
#views to Analytics
def filterByUser(request):
return “sucess”
urls.py
path(r’ajax/filter_by_user’, filterByUser, name=“filterByUser”)