There is a problem that when adding a record or when changing it, an error occurs in the admin panel.

page not found

And this happens only with a POST request and the presence in the form input type=file . I want to debug, but I don’t know which piece of code works when adding a record. Maybe someone knows?

Error adding record with file

Thanks Mikhail Alekseevich. This showed exactly where the error occurs. But I did not understand anything. Can you understand?

Trace back: enter image description here

  • one
    Debug=True , lower down, there will be a log. The "piece of code" that is written in your view should be viewed there. - matz
  • I would first try manage.py makemigrations, manage.py migrate. - Mikhail Alekseevich
  • @ MikhailAlekseevich Delal, this is not the problem. This problem occurs on Cpanel, and locally everything works - Citizen
  • ~ Citizen, do you have apache there? Try to turn off Debug = True, the output will show 404 of the corresponding server :) - Mikhail Alekseevich
  • @ MikhailAlekseevich Yes apache, set Debug = False, issued a simple error "Not Found. The requested URL / admin / main / gallery / add / was not found on this server". - Citizen

1 answer 1

In order to find out the location of the error, you can use handler404 in urls.py + sys + traceback:

urls.py:

  import sys, traceback from django.http import HttpResponse def test_404(request): exc_type, exc_value, exc_traceback = sys.exc_info() ex_info = traceback.format_tb(exc_traceback) + \ traceback.format_exception(exc_type, exc_value, exc_traceback) + \ traceback.format_exception(exc_type, exc_value, exc_traceback) return HttpResponse(str(ex_info), status=404) handler404 = test_404 

Will work only when

 DEBUG = False 

In settings.py