I have a Django app hosted on Heroku, and my stylesheet isn't loading. Now I've taken the time to read the other questions on this issue, but I believe each situation is unique. Now the error is as follows:
Refused to apply style from 'https://mazzodjangoapp.herokuapp.com/static/blog/main.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
The static directory is defined in my settings.py file as:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
In my base.html file, my link tag looks like this:
<link rel="stylesheet" type="text/css" href="{% static 'blog/main.css' %}">
Works locally. Why is it not loading up in the Heroku environment?
By default, Django sets content_type to text/html. You can however, set content_type to any of the official Internet media types (MIME types) managed by IANA (for more information visit http://www.iana.org/assignments/media-types/media-types.xhtml).
A media type (also known as a Multipurpose Internet Mail Extensions or MIME type) indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.
As per the Heroku guide for configuring Django apps, you need to use pip and install django_heroku
pip install django_heroku
Add it to your settings.py
import django_heroku
And finally, add this to the bottom of the settings.py file
django_heroku.settings(locals())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With