pyinstaller: Unable to serve external files with DEBUG = True

Hi. I’m new to Django and pyinstaller, and I’m a new member of a team that has inherited a Django project that’s being built using pyinstaller.

When we build our installer with DEBUG = True (the default), it works fine.

We can load images, .js, .css etc. just fine.

When we build without DEBUG = True, however, the server refuses to load any external file.

For example, our main .js file yields the following error:

Refused to execute script from 'http://localhost:8000/static/static/js/main.5b32b158.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

(Yes, that file path is correct.)

The content-type response header is always “text/html”.

Manually adding “type” declarations to the <script> tags does not resolve the issue.

We get the same error even just trying to load images with an <img> tag.

We have the following:

ALLOWED_HOSTS = [‘localhost’, ‘’]

Is there some setting we need to enable serving of external files?

Many thanks in advance!

See the docs at How to deploy static files | Django documentation | Django and How to manage static files (e.g. images, JavaScript, CSS) | Django documentation | Django .

In a real production-quality deployment, you would not be using Django to serve static files. That would be more appropriately handled by your web server.