亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Gin-golang:使用樣式表加載 html 文件

Gin-golang:使用樣式表加載 html 文件

Go
幕布斯6054654 2021-12-27 17:46:05
我的英語很基礎,對不起:)好吧,我的問題是,當 Gin 加載 HTML 時,我的 HTML 文件包含導入 (/stylesheet/index.css),因此當使用 Gin 運行我的應用程序時,此警報不會加載樣式表文件workspace/          main/               main.go          templates/                   index.tmpl.html                   css/                       index.cssmain.gor.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    })})索引.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>索引.cssheader {   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; }所以,我正在運行我的應用程序,這在 Gin 模式調試中給了我錯誤 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 文件時,這顯示樣式表沒有問題。:(我不知道如何使用 Gin 加載樣式表。請幫忙。PS:我需要使用杜松子酒
查看完整描述

2 回答

?
慕勒3428872

TA貢獻1848條經驗 獲得超6個贊

您需要一個處理main.go. 使用靜態。

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


查看完整回答
反對 回復 2021-12-27
?
阿波羅的戰車

TA貢獻1862條經驗 獲得超6個贊

在您的 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>


查看完整回答
反對 回復 2021-12-27
  • 2 回答
  • 0 關注
  • 522 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號