在beegae中使用CSS

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

Using CSS in beegae

问题

我正在使用Beegae包和Google Cloud SDK。我的项目可以正常运行,但是我在访问CSS文件时遇到了问题。它位于项目根目录下的static\css文件夹中(我使用的是Windows系统)。我尝试了SetStaticPath方法、将DirectoryIndex设置为true以及直接设置静态路径。我的HTML代码如下:

<link rel="stylesheet" href="/static/css/style.css" type="text/css" />

但是我一直得到以下错误信息:

INFO 2014-07-29 07:16:47,546 module.py:640] default: "GET /static/css/style.css HTTP/1.1" 404 2010

目前我的路由器代码如下:

package routers

import (
	"beegoapp2/controllers"
	"github.com/astaxie/beegae"
)

func init() {
	beegae.DirectoryIndex = true
	beegae.SetStaticPath("/static/css", "static/css")
	//	beegae.StaticDir["/static"] = "static"
	beegae.Router("/", &controllers.MainController{})
	beegae.Router("/home/index", &controllers.MainController{})
	beegae.Router("/band/add", &controllers.BandAddController{})
	beegae.Router("/band/verify", &controllers.BandVerifyController{})
	beegae.Router("/album/index/:id", &controllers.AlbumIndexController{})
	beegae.Router("/album/add/:id", &controllers.AlbumAddController{})
	beegae.Router("/album/verify/:id", &controllers.AlbumVerifyController{})
	beegae.Router("/home/genrelist", &controllers.GenreListController{})
	beegae.Router("/home/bygenre/:id", &controllers.ByGenreController{})
}

如果有人能够解决这个问题,我将非常感激。

英文:

I'm using the Beegae package and Google Cloud SDK. My project works, but I'm having trouble accessing my CSS file. It's located in static\css in my project's root (I use Windows). I tried SetStaticPath, setting DirectoryIndex to true, and setting the static path directly. My html is

&lt;link rel=&quot;stylesheet&quot; href=&quot;/static/css/style.css&quot; type=&quot;text/css&quot; /&gt;

and I keep getting

INFO 2014-07-29 07:16:47,546 module.py:640] default: "GET /static/css/style.css HTTP/1.1" 404 2010

Currently my router code is

package routers

import (
	&quot;beegoapp2/controllers&quot;
	&quot;github.com/astaxie/beegae&quot;
)

func init() {
	beegae.DirectoryIndex = true
	beegae.SetStaticPath(&quot;/static/css&quot;, &quot;static/css&quot;)
	//	beegae.StaticDir[&quot;/static&quot;] = &quot;static&quot;
	beegae.Router(&quot;/&quot;, &amp;controllers.MainController{})
	beegae.Router(&quot;/home/index&quot;, &amp;controllers.MainController{})
	beegae.Router(&quot;/band/add&quot;, &amp;controllers.BandAddController{})
	beegae.Router(&quot;/band/verify&quot;, &amp;controllers.BandVerifyController{})
	beegae.Router(&quot;/album/index/:id&quot;, &amp;controllers.AlbumIndexController{})
	beegae.Router(&quot;/album/add/:id&quot;, &amp;controllers.AlbumAddController{})
	beegae.Router(&quot;/album/verify/:id&quot;, &amp;controllers.AlbumVerifyController{})
	beegae.Router(&quot;/home/genrelist&quot;, &amp;controllers.GenreListController{})
	beegae.Router(&quot;/home/bygenre/:id&quot;, &amp;controllers.ByGenreController{})
}

If anyone can shed some light on this problem, I'd greatly appreciate it.

答案1

得分: 2

我通过更改我的app.yaml文件解决了这个问题。我在"handlers"部分添加了以下几行代码:

- url: /static/css
  static_dir: static/css
  mime_type: "text/css"

我建议在使用Google App Engine时遇到静态文件问题的人尝试类似的更改。

英文:

I solved the problem by changing my app.yaml. I added the following lines to the "handlers" section:

- url: /static/css
  static_dir: static/css
  mime_type: &quot;text/css&quot;

I suggest a similar change to anyone having trouble with static files while using Google App Engine.

答案2

得分: 0

Ross Albertson的答案对我没有起作用。这是我对这个问题的解决方案。将app.yaml文件的handlers部分更改如下...

handlers:               
                    
- url: /static          
  static_dir: ../static 
                    
- url: /.*              
  script: _go_app       

这不仅对css有帮助,对于js、图片等所有其他文件也是如此。

英文:

Ross Albertson's answer didn't worked for me. Here is my solution for this problem. Change the app.yaml file's handlers part as follows...

handlers:               
                    
- url: /static          
  static_dir: ../static 
                    
- url: /.*              
  script: _go_app       

This will be helpful not only for css but also for every other files like js, images etc.

huangapple
  • 本文由 发表于 2014年7月29日 20:45:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/25015661.html
匿名

发表评论

匿名网友

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

确定