英文:
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
<link rel="stylesheet" href="/static/css/style.css" type="text/css" />
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 (
"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{})
}
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: "text/css"
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论