Django Admin with Periodic Return 404

We use Django Admin to store some data that is exported to some of our sites. Sometimes, when you look at the standard change list view to get the model edit form instead of being redirected to the correct page, we get a Django 404 page / template.

This happened a bit sporadically, and we could play it for a while, rebooting three times:

  • First F5: 404
  • Second F5: 404
  • Third F5: Object change form loads correctly

But recently, he often returned 404 times. This seems to reduce the chance of a 404 return when we give up apache (gracefully) and get worse (again, apparently) with a lot of requests.

Running Django 1.2.1 on Fast-CGI / MySQL 5.1.x

FWIW, I can’t reproduce the problem on my virtual machine, but I run mod_wsgi and have Debug = True in the settings. Otherwise, the code and the database are identical.

+4
source share
3 answers

I had the same problem. The solution for me was to transfer my calls to admin.site.register() to admin.py . If DEBUG is set to false, your models load lazily, so registration requests are not always received. Apparently admin.py always loads during init.

+4
source

I had the same problem until last week. after I track this error for several months and I found a 404 increase in django source code.

i changed the /path/to/django/contrib/admin/options.py get_object () method of the ModuleAdmin class. Note: I am using Django 1.3.1

somehow django cannot find an object with pk object_id in the request. so I changed it like this:

 def get_object(self, request, object_id): .... queryset = self.queryset(request) model = queryset.model obj = None #first search the object with original way try: object_id = model._meta.pk.to_python(object_id) obj = queryset.get(pk=object_id) except: #print "DEBUG: > first try does not exist (%s)" % str(object_id) obj = None if obj is None: #if object doesn't exist in queryset, search in db try: object_id = model._meta.pk.to_python(object_id) obj = model.objects.get(pk=object_id) #print "DEBUG: > second try found %s" % str(obj) except (model.DoesNotExist, ValidationError): #print "DEBUG: > second try does not exist" obj = None return obj 

I know that it’s not good to change something in the django source, so use it at your own risk!

+1
source

See if there is an alternative WSGI script at the end:

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

has the meaning.

0
source

Source: https://habr.com/ru/post/1314442/


All Articles