I know this question has been asked before but I have tried to implement the answers to those forums but none have worked for me so far.
Here is my html file:
{% include 'main.html' %}
{% load static %}
<head>
<link rel="stylesheet" type="text/css" href="projects.css"/>
</head>
<body>
<h1 style="text-align: center">Projects</h1>
<h1>{{projects}}</h1>
{% for project in context %}
{% with 'jweb/images/'|add:project.image as project_photo %}
<div class="card-wrap">
<div class="card">
<h2 class="card-header">{{project.title}}</h2>
<div class="card-image">
<img src="{% static project_photo %}">
</div>
</div>
</div>
{% endwith %}
{% endfor %}
</body>
{% include 'pagebottom.html' %}
Here is my css:
.card-wrap{
width: auto;
}
.card{
background: blue;
padding:3rem;
border:none;
box-shadow: 0 2px 5px 0 rgb(0,0,.2);
border-radius: .25rem;
}
.card-image{
min-width: 0;
min-width: 0;
}
.card-image > img{
height:100%;
width:100%;
object-fit:contain;
}
Here is my settings.py:
import os
import mimetypes
mimetypes.add_type("text/css", ".css", True)
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"blog"
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "jweb.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
BASE_DIR / 'templates'
],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = "jweb.wsgi.application"
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}
STATIC_URL = "static/"
STATICFILES_DIRS = [
BASE_DIR / 'static'
]
Here is my folder:
I keep getting a 404 error: Refused to apply style from 'http://127.0.0.1:8000/projects/projects.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. It seems like I had the correct link statement in my html file and have tried to add text/css mimetypes but it keeps spitting the error.