LoginSignup
9
1

More than 3 years have passed since last update.

djangoでhtmlに画像を埋め込む

Last updated at Posted at 2019-04-06

問題点

現在、Djangoで自己紹介ページを作っています。
そこで躓いた点があります。

index.html
<img src="images/○○○○.jpg" width="100" height="100" >

webページ上で、上記のhtmlによって画像を表示しようとしても表示されませんでした。

解消策

Djangoで画像を表示しようとする際には、以下のように記述する必要がありました。

index.html
{% load static%}  #staticフォルダを読み込む
<img src="{% static "images/○○○○.jpg"%}" width="100" height="100">

まとめ

{% static ""%}で囲むことによって問題が解消しました。
Djangoを使うにあたって、{% static ""%}だけでなく{% url "" %}などのタグがあるようです。
まだDjangoを学び始めて1週間くらいなのでこれから実力をつけていきたいです。

9
1
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
9
1