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条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法