使用Martini显示HTML、CSS和Javascript

huangapple go评论74阅读模式
英文:

Displaying HTML, CSS and Javascript with Martini

问题

我正在尝试使用Martini构建一个聊天室。

我使用Bootstrap编写了一些HTML、CSS和JS,并希望使用Martini来显示它。我能够轻松地显示一个"Hello world"的index.html文件,但是当我用我想要渲染的代码(聊天室布局)替换index.html文件时,它尝试使用GET请求调用js/和css/文件,但失败了。

具体来说,这是输出的内容:

[martini] listening on :3000
[martini] Started GET /
[martini] Completed 200 OK in 570.573us
[martini] Started GET /index.html
[martini] Completed 200 OK in 1.188084ms
[martini] Started GET /js/chatclient.js
[martini] Completed 404 Not Found in 614.137us
[martini] Started GET /js/bootstrap.min.js
[martini] Completed 404 Not Found in 417.855us
[martini] Started GET /css/bootstrap.min.css
[martini] Completed 404 Not Found in 440.463us

有关如何使JavaScript正常工作的建议吗?从简单的谷歌搜索中,我找不到关于使用Martini渲染CSS和JS的任何信息,这就是为什么我在这里发帖的原因。

英文:

I'm trying to build a chatroom using Martini.

I put together some HTML, CSS and JS using Bootstrap, and now I want to display it using Martini.
I'm able to display a "Hello world" index.html file without much trouble, but when I replace index.html file with the code I want it to render (the chat room layout), it tries calling the js/ and css/ files using GET requests and fails.

Specifically, this is the output :

[martini] listening on :3000
[martini] Started GET /
[martini] Completed 200 OK in 570.573us
[martini] Started GET /index.html
[martini] Completed 200 OK in 1.188084ms
[martini] Started GET /js/chatclient.js
[martini] Completed 404 Not Found in 614.137us
[martini] Started GET /js/bootstrap.min.js
[martini] Completed 404 Not Found in 417.855us
[martini] Started GET /css/bootstrap.min.css
[martini] Completed 404 Not Found in 440.463us

Any advice on how I can get the Javascript to work? From a simple Google search I couldn't find anything regarding being able to render CSS and JS using Martini, which is why I posted here.

答案1

得分: 1

没问题,我明白了。

这是一个简单的代码片段:

m.Use(martini.Static("<assets路径>"))

请注意,<assets路径>需要替换为实际的路径。

英文:

Never mind, got it -

Its a simple

m.Use(martini.Static(&lt;path to assets&gt;))

huangapple
  • 本文由 发表于 2014年4月20日 06:42:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/23176403.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定