前提
css反映のさせかたが曖昧だったので記述します。
【環境】
os
python3.7.3
Django3.0.5
アプリケーション名:sns
【ファイル構成】
sns
| - snsproject
| | - setting.py
| | - urls.py
| - snsapp
| | - urls.py
| | - views.py
| - templates
| | - sns
| | | - index.html
| - static
| | - css
| | | - style.css
|manage.py
本題
早速実装していきます。
settings.py
・・・INSTALLED_APPS=['django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','sns',#追記
]・・・TEMPLATES=[{'DIRS':[os.path.join(BASE_DIR,'templates'),#追記
],],},},]・・・STATIC_URL='/static/'STATICFILES_DIRS=([os.path.join(BASE_DIR,"static"),#追記
])
続いてtemplates/index.htmlを編集していきます。
index.html
{% load static %}
<!DOCTYPE html><htmllang="ja"><head><metahttp-equiv="Content-type"content="text/html; charset=utf-8"/><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=device-width, initial-scale=1"><title>sns</title><linkhref="{% static 'css/stylesheet.css' %}"rel="stylesheet"></head><body></body></html>
これでCSSが反映されるようになりました。