Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mime Type Issue Loading CSS With Django App

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?

like image 209
Ironman Avatar asked Jan 29 '20 17:01

Ironman


People also ask

What is mime type in Django?

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).

What is mime type in HTML?

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.


1 Answers

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())
like image 144
thedavl Avatar answered Sep 25 '22 12:09

thedavl