i inserted a css file to my django project (in 'static' directory) and set address of this css to my index.html file (in 'template' directory) according to django dacumentation but my css dosn't work!
this is my addresses:
myproject/myapp/templates/html/index.html
myproject/myapp/static/css/index.css
this is my html:
{% load static %}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head lang="eng">
<link rel="stylesheet" type="text/css" href={% static "css/index.css" %}/>
</head>
<body onload="myFunction()">
----some code----
</body>
</html>
this is my settings.py file:
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__)))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '83lia*q_t0q%=hm==3#s*h$=s5(4!l44s698r326zgpz*v4csl'
# 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',
'myapp',
]
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 = 'myproject.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
'././myapp/templates/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 = 'myproject.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
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',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'myapp/static')
]
this is my urls.py:
from django.contrib import admin
from django.urls import path , include
admin.autodiscover()
urlpatterns = [
path('admin/', admin.site.urls),
path('myapp/', include('myapp.url')),
]
this is url.py file in myapp directory:
from django.urls import path , include
from . import views
urlpatterns = [
path('', views.index, name = 'index'),
]
and this is my veiws.py fie:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return render(request, 'index.html',{})
but my css dosn't work!i get 404 error! please help me to run myproject completely