gpt4 book ai didi

twitter-bootstrap - 在 tmpl 文件中使用 bootstrap 来显示导航栏

转载 作者:IT王子 更新时间:2023-10-29 01:40:41 26 4
gpt4 key购买 nike

我正在尝试使用 GO 制作一个简单的导航栏。

围棋服务器:

func main() {
tmpl := template.Must(template.New("navigator.tmpl").ParseFiles("./templates/navigator.tmpl"))

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data := Names{
PageTitle: "Holy Moly",
}


tmpl.Execute(w, data)
})
if err := http.ListenAndServe(":8080", nil); err != nil {
panic(err)
}
}

这是我的模板文件导航器.tmpl

{{ define "navigator" }}<!DOCTYPE html> {{ end }}
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<title>Dashboard Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="/go/src/dashboard/assets/dist/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="dashboard.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
</button>
<a class="navbar-brand" href="#">{{.PageTitle}}</a>
</div>
</body>
</html>

我的目录结构如下

开始:

=>来源

  =>dashboard

=> main.go

=> assets

=>dist

=>bootstrap

=>dist

=>css/bootstrap.min.css

我无法获得任何 Bootstrap 图形。我看到了标题名称,但没有看到矩形导航栏。

当我直接在浏览器中打开文件时,我可以看到带有标题的导航栏图像。

我现在不确定为什么 Bootstrap 图形没有正确呈现

最佳答案

我假设您还没有为静态 Assets 创建任何路由。所以创建一个。

http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("assets"))))

通过添加上述处理程序,每个带有 /static/ 前缀的请求都将使用 assets 文件夹中的静态文件提供服务。

接下来,只需更改静态 Assets 的 url。

<link href="/static/dist/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/dashboard.css" rel="stylesheet"> <!-- I'm not sure where do you put the `dashboard.css` file, so just adjust this one -->

关于twitter-bootstrap - 在 tmpl 文件中使用 bootstrap 来显示导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53843166/

26 4 0