LoginSignup
13
8

More than 5 years have passed since last update.

 DjangoでCSSファイルを読み込む方法

Posted at

DjangoでCSSファイルを読み込む方法

1.settings.pyにて以下のコードを記入

settings.py
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

2.Templateファイルにて以下のコードを記入
 (ただし、必ず {% extends 'base.html' %} が先頭で記載されなければならない)

~.html
{% load static %}

3.テンプレートファイル(基本はbase.html)に以下のコードを記入
 この場合はstatic/app.cssのディレクトリです。

base.html
<link rel="stylesheet" href="{% static 'app.css' %}">

以上で無事に反映されるはずです!!

13
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
8