14
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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' %}">

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

14
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
14
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?