Error al cargar Datatable al integrar POST
Error al cargar Datatable al integrar POST
Hola buenas tarde!!
Tengo una pregunta subi mi proyecto ya a mi dominio todo carga bien en local pero en produccion ya no me carga como deberia mi tabla una de ellas es que coloque un serverside con ajax en metodo post este mi codigo en el lenguaje donde lo tengo es en python con django
view.py
class ListPensioner(ListView):
model = Pensioner
template_name = 'pensioner.html'
@method_decorator(csrf_exempt)
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)
def get_queryset(self):
coincidencia = self.request.POST.get('filtro')
if coincidencia:
queryset = self.model.objects.filter(name__icontains=coincidencia).values()
else: queryset = self.model.objects.all().values()
return queryset
def post(self, request, *args, **kwargs):
data = self.get_queryset()
inicio =int(request.POST.get('inicio'))
fin = int(request.POST.get('limite'))
list_data = []
for indice, valor in enumerate(data[inicio:inicio+fin], inicio):
list_data.append(valor)
data = {
'length': data.count(),
'objects': list_data
}
return HttpResponse(json.dumps(data, default=str), 'application/json')
script
var tabla; $(document).ready(function() { table = $('#list_pensioners').DataTable( { serverSide:true, processing: true, responsive: true, destroy: true, ordering: false, autowidth:true, deferRender: true, paging:true, ajax: function (data, callback, settings) { $.post(window.location.pathname, { limite: data.length, inicio: data.start, filtro: data.search.value }, function (res) { callback({ recordsTotal: res.length, recordsFiltered: res.length, data: res.objects }); }, ) }, columns: [ {'data': "nss"}, {'data': "maternal"}, {'data': "paternal"}, {'data': "name"}, ], "language": { "url": "https://cdn.datatables.net/plug-ins/1.10.21/i18n/Spanish.json" }, }); });pero me manda un error en la consola POST (403 forbidden)
alguien me podria asesorar como solucionarlo ya que cada ves que integro algo en el ajax me desaparece el buscador y la paginacion
Replies
Your server is responding with the 403 error. You will need to look at the server/Django logs to determine why its responding with a 403. Here is some info about the 403 error:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403
Kevin
oh gracias
When I submit my table after a user edits it, an ajax call executes a stored procedure which returns the updated data in a json format. This format comes in a different order, and not all of the fields are consistent.
@Bombardier - I've removed your link as it looks like spam. I might be wrong though, and if so apologies. If I am, please clarify your question and how it relates to this thread?
Allan