2016-03-26 47 views
2

我的英语加载HTML文件是很基本的,对不起:)杜松子酒golang:用样式表

嗯,我的问题是,当晶晶被加载HTML,我的HTML文件包含导入(/样式表/索引的CSS),这样,当运行我的应用程序杜松子酒,此警报是不加载样式表文件

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 THIS 
    }) 
}) 

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 is the capital city of England. It is the most populous city in the United Kingdom, 
with a metropolitan area of over 13 million inhabitants.</p> 
    <p>Standing on the River Thames, London has been a major settlement for two millennia, 
its history going back to its founding by the Romans, who named it 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; 
} 

所以,我捉迷藏我的应用程序,这给我杜松子酒模式调试错误404。

[GIN] 2016/03/26 - 12:10:50 | 200 |  688.938µs | 127.0.0.1 | GET  /index 
[GIN] 2016/03/26 - 12:10:50 | 404 |  2.865µs | 127.0.0.1 | GET  /css/index.css 

另一方面,当我只加载html文件时,这显示样式表没有问题。 :(

我不知道如何与杜松子酒加载样式表

帮助,请

PS:我需要用杜松子酒

回答

5

您需要main.go对静态文件的处理程序。 。使用Static

r.Static("/css", "../templates/css") 
-1

在你index.tmpl.html文件尝试更换如下:

<style type="text/css" media="screen"> 
    <!-- 
     @import url("/css/index.css"); 
    --> 
</style> 

这一个:

<style type="text/css" media="screen"> 
    <!-- 
     @import url("css/index.css"); 
    --> 
</style> 
相关问题