Since the method of reflecting css was ambiguous, I will describe it.
【environment】 os python3.7.3 Django3.0.5
Application name: sns
【file organization】 sns | - snsproject | | - setting.py | | - urls.py | - snsapp | | - urls.py | | - views.py | - templates | | - sns | | | - index.html | - static | | - css | | | - style.css |manage.py
I will implement it immediately.
settings.py
・ ・ ・
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'sns', #Postscript
]
・ ・ ・
TEMPLATES = [
{
'DIRS': [
os.path.join(BASE_DIR, 'templates'), #Postscript
],
],
},
},
]
・ ・ ・
STATIC_URL = '/static/'
STATICFILES_DIRS = (
[
os.path.join(BASE_DIR, "static"), #Postscript
]
)
Next, edit templates / index.html.
index.html
{% load static %}
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>sns</title>
<link href="{% static 'css/stylesheet.css' %}" rel="stylesheet">
</head>
<body>
</body>
</html>
The CSS is now reflected.
Recommended Posts