Problem: Static resources (images, js, css, etc.) lead to 404 errors.
Potential fix: A similar question was posted here and here. This is actually by design, as django is not meant to server static resources when DEBUG=False.

Basically, when you’re in DEBUG mode, static files are being served via the staticfiles app (which uses settings like STATICFILES_DIRS and STATICFILES_FINDERS to properly locate your static resources). When DEBUG=FALSE, the staticfiles app doesn’t run and your static resources aren’t being referenced correctly by the django webserver. However, if you were to host the files are an actual webserver, the STATIC_URL settings should hold up.

There is a way to force the staticfiles app to run in DEBUG=FALSE mode though, which can be useful when you want to test a deployment locally with django. You just have to add an --insecure flag when you run the django webserver: runserver --insecure

As noted here, the --insecure option should only be used for testing purposes.

This article has 1 comments

  1. Sony Reply

    This work fine if i used –insecure but what if i dont want to use –insecure?/
    I want should work without using –insecure during the server run.
    Give a solution.

Leave a Comment

Your email address will not be published. Required fields are marked *