dongqiang8683 2012-12-14 12:39
浏览 28
已采纳

如何在Go,Google App Engine中使用外部CSS和(静态)图像

I'm working on a webpage in Go. The Go code uses "html/template" to parse HTML. I would like to use CSS in the project. Everything is working well when I use internal CSS code, but when I would like to change to external it dosen't work. It looks like it can't access to the .css file.

Here is my app.yaml configuration:

application: makerboardstest
version: 1
runtime: go
api_version: go1

handlers:
- url: /.*
  script: _go_app

- url: /stylesheets
  static_dir: stylesheets

- url: /images
  static_dir: images 

Here is how I would like to access to the .css from the html:

<head>
<link href="/stylesheets/main.css" media="screen" rel="Stylesheet" type="text/css" />
</head>

I also have problems with (static) images. I would like to access to the image with this html code:

<img src="/images/img1.jpg" />

What can be the problem?

(I'm testing it on my PC, Win 7)

  • 写回答

1条回答 默认 最新

  • duanqiao2225 2012-12-14 12:46
    关注

    The handlers are checked in order, and your first handler matches everything; move your static handlers up above it. In other words, when your browser makes a request for /stylesheets/main.css, it matches the /.* pattern of your first handler and asks go to serve it rather than trying the static dir. If you flip the order of the handlers, it will match /stylesheets first and serve it from the static dir.

    i.e.:

    handlers:
    - url: /stylesheets
      static_dir: stylesheets
    
    - url: /images
      static_dir: images 
    
    - url: /.*
      script: _go_app
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog