my english basic, i'm sorry :)
well, problem when gin loading html, html file contains import (/stylesheet/index.css), when run app gin, alert not load stylesheet file
workspace/ main/ main.go templates/ index.tmpl.html css/ index.css
main.go
r.loadhtmlfiles("../templates/index.tmpl.html") r.get("/index", func(c *gin.context) { c.html(200, "index.tmpl.html", gin.h{ "title": "main website", //ignore }) })
index.tmpl.html
<!doctype html> <head> <title>hola titulo</title> <style type="text/css" media="screen"> <!-- @import url("/css/index.css"); --> </style> </head> <body> <header> <h1>city gallery</h1> </header> <nav> london<br> paris<br> tokyo </nav> <section> <h1>london</h1> <p>london capital city of england. populous city in united kingdom, metropolitan area of on 13 million inhabitants.</p> <p>standing on river thames, london has been major settlement 2 millennia, history going founding romans, named londinium.</p> </section> <footer> copyright © w3schools.com </footer> </body> </html>
index.css
header { background-color:black; color:white; text-align:center; padding:5px; } nav { line-height:30px; background-color:#eeeeee; height:300px; width:100px; float:left; padding:5px; } section { width:350px; float:left; padding:10px; } footer { background-color:black; color:white; clear:both; text-align:center; padding:5px; }
so, runnning app , give me error 404 in gin mode debug.
[gin] 2016/03/26 - 12:10:50 | 200 | 688.938µs | 127.0.0.1 | /index [gin] 2016/03/26 - 12:10:50 | 404 | 2.865µs | 127.0.0.1 | /css/index.css
on other hand when load html file only, shows stylesheet without problems. :(
i not know how load stylesheet gin.
help, please.
ps: need use gin
you need handler static files in main.go
. use static.
r.static("/css", "../templates/css")
Comments
Post a Comment