dstbp22002 2018-07-26 23:00
浏览 60
已采纳

使用本地版本时丢失BootStrap格式

I'm writing my first web server, so don't hate.

I am using Golang and HTML with BootStrap.

This program will eventually run on a Raspberry Pi in a small device. So I assume it would be best to use a downloaded version of BootStrap rather than the CDN version right?

But when I do this, my buttons on my page lose their formatting.

Here is my HTML code using the CDN version:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Cacophonator Setup</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Cacophonator Setup</h2>
  <div class="col-sm-12">
        <!-- <a href="\CameraPositioning\" class="btn btn-primary" type="button">Camera Positioning</a> -->
    <button type="button" class="btn btn-primary" onclick="location.href='camera-positioning.html'">Camera Positioning</button>
  </div>
  <div class="col-sm-12">
        <button type="button" class="btn btn-primary" onclick="location.href='3G-connectivity.html'">3G Connectivity</button>
  </div>        
  <div class="col-sm-12">
      <button type="button" class="btn btn-primary" onclick="location.href='API-server.html'">API Server</button>
  </div>
  <div class="col-sm-12">
    <button type="button" class="btn btn-primary" onclick="location.href='network-interfaces.html'">Network Interfaces</button>
  </div>

  <div class="col-sm-12">
    <button type="button" class="btn btn-primary" onclick="location.href='disk-memory.html'">Disk and Memory Status</button>
  </div>

</div>

<h4>{{.Head}}<h4>

</body>
</html>

Here is the new HTML which is not working:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Cacophonator Setup</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href = "css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

  <script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Cacophonator Setup</h2>
  <div class="col-sm-12">
        <!-- <a href="\CameraPositioning\" class="btn btn-primary" type="button">Camera Positioning</a> -->
    <button type="button" class="btn btn-primary" onclick="location.href='camera-positioning.html'">Camera Positioning</button>
  </div>
  <div class="col-sm-12">
        <button type="button" class="btn btn-primary" onclick="location.href='3G-connectivity.html'">3G Connectivity</button>
  </div>        
  <div class="col-sm-12">
      <button type="button" class="btn btn-primary" onclick="location.href='API-server.html'">API Server</button>
  </div>
  <div class="col-sm-12">
    <button type="button" class="btn btn-primary" onclick="location.href='network-interfaces.html'">Network Interfaces</button>
  </div>

  <div class="col-sm-12">
    <button type="button" class="btn btn-primary" onclick="location.href='disk-memory.html'">Disk and Memory Status</button>
  </div>

</div>

I have only changed 2 lines, so that I use (or try to) the local BootStrap CSS and JS.

And I call it from Go like this:

http.HandleFunc("/", managementinterface.IndexHandler)
log.Fatal(http.ListenAndServe(":8080", nil))

And IndexHandler is like this:

func IndexHandler(w http.ResponseWriter, r *http.Request) {

    t, _ := template.ParseFiles("../html/index.html")
    t.Execute(w, "")

}

One final note: The CDN version is 3.3.7, the version I downloaded is 4.1.1

And also if I look at the local BootStrap CSS file, I can see this:

.btn-primary {
  color: #fff;
  background-color: #007bff;
  border-color: #007bff;
}

Which is the styling I want. Any help appreciated, thanks.

  • 写回答

2条回答 默认 最新

  • douwulu2576 2018-07-29 05:13
    关注

    it turns out someone else on this open source project answered this.

    What they did was pack all the static css and html pages into the Go executable. They did this with a package called packr: https://github.com/gobuffalo/packr

    It's a tool that does that for you.

    So then you have only 1 file to deploy, which is really nice.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料