[Django] #29571: Error 500 when accessing static files that do not exist

1 view
Skip to first unread message

Django

unread,
Jul 17, 2018, 7:40:34 PM7/17/18
to django-...@googlegroups.com
#29571: Error 500 when accessing static files that do not exist
-----------------------------------------------+------------------------
Reporter: dmitriybch | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------------+------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29571>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 17, 2018, 9:05:27 PM7/17/18
to django-...@googlegroups.com
#29571: Error 500 when accessing static files that do not exist
-------------------------------------+-------------------------------------
Reporter: dmitriybch | Owner: nobody
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 2.0
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ramiro Morales):

* status: new => closed
* resolution: => needsinfo


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29571#comment:1>

Reply all
Reply to author
Forward
0 new messages