In my Django project I added a new 404 page, that gets called when I enter an invalid url. But, the CSS file is not loaded with page, so it appears mis-formatted.
The browser gives me this error: "Refused to apply style from because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled."
The point is, There are other CSS files in the 'static' folder that are loaded correctly without this error, like the bootstrap.css file...
My settings.py
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'collected_static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/media')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
My urls.py
urlpatterns = [
...
]
handler400 = 'utils.views.error_400'
handler403 = 'utils.views.error_403'
handler404 = 'utils.views.error_404'
handler500 = 'utils.views.error_500'
My utils.views.py
def error_400(request, exception):
data = {}
return render(request, 'utils/mv_admin_400.html', data)
def error_403(request, exception):
data = {}
return render(request, 'utils/mv_admin_403.html', data)
def error_404(request, exception):
data = {}
return render(request, 'utils/mv_admin_404.html', data)
def error_500(request):
data = {}
return render(request, 'utils/mv_admin_500.html', data)
My 404.html
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="{% static 'css/handlers/error-nf.css' %}" rel="stylesheet" type="text/css" />
</head>
My Folder structure
src
- mysite
- static
-- css
--- bootstrap.css
--- handlers
---- error-nf.css
Also I tried to move the css file out of the "handlers" folder to the parent "css" folder, but error still occur.