Flatpages with DEBUG=False requires 404.html
|Reported by:||Rob Hudson <treborhudson@…>||Owned by:||adrian|
|Cc:||treborhudson@…||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
While I think it is bad to not have a 404.html, I think this could be cleaner since it does work when DEBUG=False. This could lead to a broken site when it is deployed by simply changing the DEBUG setting, which I think is bad.
If flatpages and DEBUG=False and 404.html doesn't exist it throws the error:
Traceback (most recent call last): File "/opt/local/lib/python2.4/site-packages/django/core/servers/basehttp.py", line 272, in run self.result = application(self.environ, self.start_response) File "/opt/local/lib/python2.4/site-packages/django/core/servers/basehttp.py", line 614, in __call__ return self.application(environ, start_response) File "/opt/local/lib/python2.4/site-packages/django/core/handlers/wsgi.py", line 189, in __call__ response = self.get_response(request) File "/opt/local/lib/python2.4/site-packages/django/core/handlers/base.py", line 103, in get_response return callback(request, **param_dict) File "/opt/local/lib/python2.4/site-packages/django/views/defaults.py", line 78, in page_not_found t = loader.get_template(template_name) File "/opt/local/lib/python2.4/site-packages/django/template/loader.py", line 79, in get_template source, origin = find_template_source(template_name) File "/opt/local/lib/python2.4/site-packages/django/template/loader.py", line 72, in find_template_source raise TemplateDoesNotExist, name TemplateDoesNotExist: 404.html
When DEBUG=False, get_response in core/handlers/base.py triggers the callback to the handler404 which is 'django.views.defaults.page_not_found' which eventually loads the template 404.html. If it doesn't exist, you get the error above.
When DEBUG=True, get_response loads the django.views.debug.technical_404_response.
I see two options for a fix (and one isn't really a "fix")...
- Change documentation to say that flatpages require that you have a 404.html template.
- Fix this so it works the same in both DEBUG states.
If #2 is the best option, this requires a design decision.
One fix could be to change get_response to know whether flatpages is enabled and switch the way it handles the call to page_not_found. But that couples the base handler to flatpages which is bad.
Another fix could be to change page_not_found to not try to load the 404.html template just yet if flatpages exists. But again, this couples flatpages to django/core when it is supposed to be a contrib app.
Not sure what the best answer is.
Change History (9)
comment:1 Changed 9 years ago by Simon G. <dev@…>
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Design decision needed
comment:8 Changed 7 years ago by boxed
- Resolution wontfix deleted
- Status changed from closed to reopened