In my HTML template, when I pass it to debug mode, gets the following errors:
- Refused to apply style from its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.;
[MIME Error]== Refused to apply style from 'http://localhost:63342/YouTrade1/templa ... ss'%20%%7D' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
- '{% load static %}' shows in plain text;
Код: Выделить всё
Pics and css files are in YouTrade1/static/YouTrade1 Template is in YouTrade1/templates/YouTrade1I tried several solutions for the documentation of my static files and none seem to work. All documentation according to Django best practices.
I don't manage to understand whether there's something wrong with either my django project setup (which looks fine), my testing environment (I click debug/run on pyCharm IDE and they said it's all fine on their side) or my HTML script.
SETTINGS
Код: Выделить всё
""" Django settings for YouTrade1 project. Generated by 'django-admin startproject' using Django 5.0.2. For more information on this file, see https://docs.djangoproject.com/en/5.0/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/5.0/ref/settings/ """ from pathlib import Path import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = xxx # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] 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', 'whitenoise.middleware.WhiteNoiseMiddleware', ] ROOT_URLCONF = 'YouTrade1.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': os.path.join(BASE_DIR, 'YouTrade1', 'templates/YouTrade1/YT_AboutUs.html', 'templates/YouTrade1/YT_Creators.html', 'templates/YouTrade1/YT_Investors.html'), '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 = 'YouTrade1.wsgi.application' # Database # https://docs.djangoproject.com/en/5.0/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } } # Password validation # https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # Internationalization # https://docs.djangoproject.com/en/5.0/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/5.0/howto/static-files/ STATIC_URL = '/static/' STATICFILES_DIRS = [os.path.join(BASE_DIR, 'templates/YouTrade1/static/YouTrade1'),] WHITENOISE_MIMETYPES = { '.css': 'text/css', } # Default primary key field type # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' Код: Выделить всё
from django.contrib import admin from django.urls import path from django.conf.urls.static import static from django.conf import settings from django.contrib.staticfiles.urls import staticfiles_urlpatterns from .views import home1 urlpatterns = [ path('admin/', admin.site.urls), path('YouTrade1\YT_Creators.html', home1, name='home1'),] urlpatterns += staticfiles_urlpatterns() Код: Выделить всё
from django.http import HttpResponse from django.template import loader from django.shortcuts import render def home1(request): context = {"YT_Creators": "home1"} return render(request, "YT_Creators.html", context) Код: Выделить всё
{% load static %} Creators Код: Выделить всё
body { background-image: url(BeYou.jpg); } Источник: https://stackoverflow.com/questions/781 ... -django-on
Мобильная версия