Forums

Django custom 404 page not working

my 404 page working fine on development server but when i tried it on pythonanywhere after deployment it shows

Something went wrong and the log doesn't help much


server.log file:

2020-08-09 20:09:29   File "/usr/lib/python3.7/logging/handlers.py", line 940, in emit#012    
self.socket.sendto(msg, self.address)
2020-08-09 20:09:29 OSError: [Errno 9] Bad file descriptor
2020-08-09 20:09:29 #012During handling of the above exception, another exception occurred:
2020-08-09 20:09:29 Traceback (most recent call last):
2020-08-09 20:09:29   File "/usr/lib/python3.7/logging/handlers.py", line 940, in emit#012    self.socket.sendto(msg, self.address)
2020-08-09 20:09:29 OSError: [Errno 9] Bad file descriptor
2020-08-09 20:09:29 #012During handling of the above exception, another exception occurred:
2020-08-09 20:09:29 Traceback (most recent call last):
2020-08-09 20:09:29   File "/usr/lib/python3.7/logging/handlers.py", line 940, in emit#012    self.socket.sendto(msg, self.address)
2020-08-09 20:09:29 OSError: [Errno 9] Bad file descriptor
2020-08-09 20:09:29 #012During handling of the above exception, another exception occurred:
2020-08-09 20:09:29 Traceback (most recent call last):
2020-08-09 20:09:29   File "/usr/lib/python3.7/logging/handlers.py", line 940, in emit#012    self.socket.sendto(msg, self.address)
2020-08-09 20:09:29 OSError: [Errno 9] Bad file descriptor
2020-08-09 20:09:29 #012During handling of the above exception, another exception occurred:
2020-08-09 20:09:29 Traceback (most recent call last):
2020-08-09 20:09:29   File "/usr/lib/python3.7/logging/handlers.py", line 940, in emit#012    self.socket.sendto(msg, self.address)
2020-08-09 20:09:29 OSError: [Errno 9] Bad file descriptor
2020-08-09 20:09:29 #012During handling of the above exception, another exception occurred:
2020-08-09 20:09:29 Traceback (most recent call last):
2020-08-09 20:09:29   File "/usr/lib/python3.7/logging/handlers.py", line 940, in emit#012    self.socket.sendto(msg, self.address)
2020-08-09 20:09:29 OSError: [Errno 9] Bad file descriptor

How does your code look like?

what file specifically ?

That looks like you're calling django.setup somewhere in your web app code. It is not necessary to call djsngo.setup in a web app and it breaks the logging that we have set up.

yes indeed i was using django.setup problem solved after removing it interesting info to know django.setup could break logs thank you !

Hi, What is the alternative to not using Django.setup() but still being able to retrieve the Django environment to run script ? Thanks a lot,

django.setup is only an issue if you use it in a web app (since it's already part of how Django runs in a web app). You can still use it for your scripts.

thanks for the quick reply, <br> I am still getting OSError: [Errno 9] Bad file descriptor but not every time, I do have some anchor tag in some of my templates that are linked to a script that has django.setup(set_prefix=False) <br> Is it what causes this error to repeat constantly ?

Yes, if you run django.setup in your web app, you will face the problem.