#29571 closed Bug (needsinfo)
Error 500 when accessing static files that do not exist
Reported by: | dmitriybch | Owned by: | nobody |
---|---|---|---|
Component: | contrib.staticfiles | Version: | 2.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi,
I have deployed static files according to the guide:
https://docs.djangoproject.com/en/2.0/howto/static-files/
Everything works fine except one thing:
When accessing non-existing static files in production with DEBUG = False it returns 500 error instead of 404 error.
Here is the error log:
2018-07-18 02:01:27,325: TypeError: 'NoneType' object is not callable
2018-07-18 02:01:27,325: File "/home/dmitriybch/.virtualenvs/venv_test/lib/python3.6/site-packages/django/contrib/staticfiles/handlers.py", line 67, in call
2018-07-18 02:01:27,325: return super().call(environ, start_response)
2018-07-18 02:01:27,325:
2018-07-18 02:01:27,326: File "/home/dmitriybch/.virtualenvs/venv_test/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 146, in call
2018-07-18 02:01:27,326: response = self.get_response(request)
2018-07-18 02:01:27,326:
2018-07-18 02:01:27,326: File "/home/dmitriybch/.virtualenvs/venv_test/lib/python3.6/site-packages/django/contrib/staticfiles/handlers.py", line 62, in get_response
2018-07-18 02:01:27,326: return super().get_response(request)
2018-07-18 02:01:27,326:
2018-07-18 02:01:27,327: File "/home/dmitriybch/.virtualenvs/venv_test/lib/python3.6/site-packages/django/core/handlers/base.py", line 81, in get_response
2018-07-18 02:01:27,327: response = self._middleware_chain(request)
For example:
Here is the correct link that works well:
https://www.umtest.ru/static/LaikaClientsSite/res/index/popularlogos/lg.png
And here is incorrect link
https://www.umtest.ru/static/LaikaClientsSite/res/index/popularlogos/lg9090909.png
That should return 404 but for some reason returns 500 error.
When I run the site on localhost it works correct both with DEBUG = True and with DEBUG = False. On production it works only if DEBUG = True.
PythonAnywhere said this is Django issue so I posted a ticket here.
Thanks.
Change History (1)
comment:1 by , 6 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
In production, the one serving your static files should be your web server not Django, and so the web server shoudl be in business of reporting 404 or other error.s
That, or there is some missing in your description of your setup.
Generally speaking and following best practices, no Python code should be running as part of the request cycle for static assets.
Do you get any more details (full tracceback, etc.) about the root reason for the 500 status error from email reporting? https://docs.djangoproject.com/en/2.0/howto/error-reporting/#server-errors
I'm closing , please reopen if you find the failure is actually in Django and if you can provide the above information.