Я создаю свой первый проект Django, и я хотел создать страницу с картинкой в качестве фона. Я следовал некоторым учебникам в Интернете, но затем, когда я запустил свой код, он показывает, что файл css не был найден.
Я уже пытался увидеть, был ли это путь к «статическому» файлу,и, возможно, это все еще есть, и я сделал это неправильно, но я не знаю, что еще делать.
Там это мои settings.py
"""
Django settings for sitetcc project.
Generated by 'django-admin startproject' using Django 2.2.5.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'o+7e$z&!3*#r3%*n$3(l7a3+(u18sj@33y(5p4_3*&*4l_lpfw'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "sitetcc/static"),
# '/var/www/static/',
)
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'core'
]
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 = 'sitetcc.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(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 = 'sitetcc.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.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/2.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/2.2/howto/static-files/
my urls.py:
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls.conf import include
from django.urls import path
from core import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('painel/all/', views.list_all_painels),
path('login/', include('core.urls')),
path('login/submit', views.submit_login),
path('', views.logado)
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
my views.py
from django.shortcuts import render, redirect
from django.views.decorators.csrf import csrf_protect
from django.contrib.auth import authenticate, login
from django.contrib import messages
from django.contrib.auth.decorators import login_required
# Create your views here.
@login_required(login_url='/login/')
def logado(request):
return render(request, 'logado.html')
def list_all_painels(request):
return render(request, 'list.html')
def login_user(request):
return render(request,'login.html')
@csrf_protect
def submit_login(request):
if request.POST:
username = request.POST.get('username')
password = request.POST.get('password')
print(username)
print(password)
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return redirect('core:logado')
else:
messages.error(request,'Usuário e senha inválido. Favor tentar novamente:')
return redirect('/login')
my list.html
<!DOCTYPE html>
<html>
<head>
{% load staticfiles %}
<link href="{% static "css/bootstrap-responsive.css" %}" rel="stylesheet">
<meta charset="utf-8">
<title>LOGIN</title>
<link rel="stylesheet" href="list.css">
</head>
<body>
<div class="box">
<h2>login</h2>
<form>
<div class="inputBox">
<input type="text" name="" required="">
<label>Username</label>
</div>
<div class="inputBox">
<input type="password" name="" required="">
<label>password</label>
</div>
<input type="submit" name="" value="Submit">
</form>
</div>
</body>
</html>
и list.css
body
{
margin: 0;
padding: 0;
font-family: sans-serif;
background: url("/static/img/sample.jpg") 50% 0 no-repeat fixed;
}
структура проекта выглядит следующим образом: https://imgur.com/a/IIT02EJ
будь как можно точнее, потому что я очень новичок в этом. Спасибо!