Is it possible to enable a 404 custom view for a Django application without changing anything at the project level?

I am creating a Django application and trying to make it as small as possible on the containing project.

I created a custom 404 view that works as expected, but only when I add handler404 to the urls.py project urls.py .

I want the custom view 404 that I wrote to apply only to this particular application, but from the information I came across it seems like this might not be possible. Adding handler404 to the urls.py application level has no effect.

Does Django support custom 404 views at the application level?

+4
source share
1 answer

Instead of ending the scan with:

 return render_to_response(...) 

Get the response object and check its status:

 out = render_to_response(...) if out.status_code==404: # redirect to your 404 page else: return out 
0
source

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


All Articles