Django platforms raising 404 when DEBUG False (there are 404 and 500 patterns)

I am using Django 1.1.1 stable. If DEBUG set to True Django flatpages works correctly; when DEBUG is False , each flat page I am trying to access causes a 404 user error (my error pattern clearly works correctly).

A web search involves creating 404 and 500 templates that I made.

I added to FlatpageFallBackMiddleware in middleware_classes, and flatpages are added to installed applications. Any ideas how I can make flatpages work?

+4
source share
5 answers

The same thing happened to me until I found that the 404 view is sending a 200 status response. So, all you have to do is add this to the view that processes your 404 response:

 def 404_handler(request): ... response = render_to_response('404.html', locals(), context_instance=RequestContext(request)) response.status_code = 404 return response 
+6
source

try adding FlatpageFallBackMiddleware to django.middleware.common.CommonMiddleware

and make sure your 404.html and 500.html files are stored in the root of your dir templates (eg: templates/404.html)

+1
source

The key checks the order of your middleware. Middleware is executed in order from top to bottom (request and presentation) and in lower order at the output (response and exception). Therefore, if you get to your 404 handler on what should be a perfectly reasonable URL for the platform, then something catches 404 before it gets to call the middleware flatpages.

0
source

Had the same error in a different context. The problem was caused by changing the urls.py file from

 from django.conf.urls.defaults import * 

to

 from django.conf.urls.defaults import include, patterns 

as pylint , but this omits the 404 handler and handler500, which are expected to be imported implicitly using import * .

to either add the ones that imported or just imported * , as django docs suggest solving the problem.

0
source

Create an error handling view that prints stacktrace import traceback;traceback.print_exc() instead of ignoring the error.

0
source

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


All Articles