0
0

More than 1 year has passed since last update.

htmlに画像を表示させる(Go)

Posted at

Goで作ったアプリケーションのhtmlに画像を表示させる試み

app/views/src/画像名.png
と画像があり、

<img src="/app/views/src/画像名.png" alt="Google_login">

パスも間違っておらず、画像ファイルも存在したが表示されず。

静的ファイルを扱う時には

	files := http.FileServer(http.Dir(config.Config.Static))
	http.Handle("/static/", http.StripPrefix("/static/", files))

とstatic(静的ファイルのURL)の設定を行って

[web]
port = 80
logfile = webapp.log
static = app/views

このようにconfig.iniに設定することで

go run main.go

でビルドしたときに表示される。

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