0
0

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 3 years have passed since last update.

Djangoで画像などのstaticファイルの読み込み

Last updated at Posted at 2021-05-09

staticフォルダを用意

プロジェクト配下にstaticフォルダを用意し、その下にアプリ名でフォルダを作成

settings.pyを編集

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

htmlファイルにて読み込で使用

html
{% load static %}
<figure class="figure">
        <img class="figure-img img-fluid rounded" src="{% static 'mysite/img1.jpg' %}">
        <figcaption class="figure-caption text-center small">写真の説明</figcaption>
</figure>

{% static 'アプリ名/img1.jpg' %}でリソースのpathを取得することができる

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?