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 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了