Python Django does not see the CSS file
I just started using Django, which I initially had a lot of problems with, but that's not the point. I launched a new project about 4 times, it turned out that through the console it did not create a complete list of folders and files and I had to create them manually. I created and added an init file everywhere so that Python sees this folder, however, when I need to insert a Banner photo for my profile, when I start the server through the console and the python manage.py runserver command, although it launches my entire HTML structure, it does not display the photo , which I inserted there initially.
I tried to change the location of the folders, I tried to change the location of the photos and it didn’t bring much results. Also, I changed settings.py and urls several times, but this also did not change anything, perhaps I made a mistake in the code or missed something?
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="{% static 'css' %}" />
<title>Your Profile</title>
</head>
<body>
<div class="container">
<div class="sidebar">
<div class="logo"><span class="tf-logo">{{ title }}</span></div>
<button class="sidebar-button">
<img src="{% static 'photo/home1.png' %}" alt="Home">
<span>
Home
</span>
</button>
<button class="sidebar-button">
<img src="{% static 'css/search2.png' %}" alt="Search">
<span>
Search
</span>
</button>
<button class="sidebar-button">
<img src="{% static 'css/envelope3.png' %}" alt="Messages">
<span>
Messages
</span>
</button>
<button class="sidebar-button">
<img src="{% static 'css/heart1.png' %}" alt="Favorites">
<span>
Favorites
</span>
</button>
</div>
<div class="flexcontainer">
<div class="profile-container">
<div class="middle">
<section class="SecondaryNick">
<div class="TopUsername">
<h3>{{ user.username }}</h3>
<span>
{% if user.sketches.count > 0 %}
{{ user.sketches.counts }} <h1>Sketches</h1>
{% else %}
<h1>No Sketches Yet</h1>
{% endif %}
</span>
</div>>
</section>
</div>
</div>
<section class="profile">
<div class="dlinayakartinka">
<img src="{% static 'banner.jpg' %}" height="300" width="933" alt="banner" id="banner"/>
</div>>
</section>
</div>>
</div>
</body>
</html>
Maybe I'm wrong and I need to add a variable there at the {{ user.banner }} level, as stated above, but I'm not sure if this will help. This is a piece of code that may cause problems.
<div class="dlinayakartinka">
<img src="{% static 'banner.png' %}" height="300" width="933" alt="banner" id="banner"/>
</div>>
urls.py
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 . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.profile, name='profile'),
]
urlpatterns += staticfiles_urlpatterns() + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
STATIC_URL = '/static/'
STATIC_ROOT = 'E:/DjangoProject/TF/TF/static'
views.py
from django.shortcuts import render
def profile(request):
context = {'title': 'Profile Page'}
return render(request, 'profile.html', context)
settings.py
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATES_DIR = BASE_DIR.joinpath('templates')
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-8t2ir6yr$swal3zr=hrly9+%j06uwlwp8-i_p18glf8uah(ecj'
# 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',
]
ROOT_URLCONF = 'TF.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['E:/DjangoProject/TF/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 = 'TF.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/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/3.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = 'E:/DjangoProject/TF/static/'
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
here are screenshots of the server, file paths, and so on.