[Django]-CSS not rendered in custom template for 404 and 500 pages django 1.8

3👍

It’s about serving static files. When you use DEBUG = True then django takes care about them otherwise your server should do it. Django in debug mode uses this view. The warning from there:

This view will only work if DEBUG is True.

That’s because this view is grossly inefficient and probably insecure.
This is only intended for local development, and should never be used
in production.

You can run your server with --insecure option just to test 404 error or you can explicilty create url for that page to check its styling:

Use the –insecure option to force serving of static files with the
staticfiles app even if the DEBUG setting is False. By using this you
acknowledge the fact that it’s grossly inefficient and probably
insecure. This is only intended for local development, should never be
used in production and is only available if the staticfiles app is in
your project’s INSTALLED_APPS setting. runserver –insecure doesn’t
work with CachedStaticFilesStorage.

👤bellum

1👍

Your handler404 and view are okay. But you don’t need them. Just a custom 404 template is enough. See: https://docs.djangoproject.com/en/1.8/topics/http/views/#the-http404-exception

In order to use the Http404 exception to its fullest, you should
create a template that is displayed when a 404 error is raised. This
template should be called 404.html and located in the top level of
your template tree.

The template is in the right location. I think the problem is serving your static files. Open developer tools in your browser to see what resources fail to load (console, network or sources tab). Inspect the paths. Is there an external style sheet link in the head section of the 404 source? (elements tab or view source code).

https://docs.djangoproject.com/en/1.8/howto/static-files/

Leave a comment