dongmao9217 2015-10-27 14:07 采纳率: 100%
浏览 43
已采纳

Go App中的模板文件读取自身而不是js和CSS文件

I've just starting learning go and I'm noodling around with web apps using the Google app engine. I've worked through the guestbook tutorial, and have now started my own project. The go part compiles just fine, but there's something strange happening when the template tries to render. It's able to render all the HTML, but I've added both CSS and JS, and the template is somehow reading in itself instead of the respective CSS and JS files. It's bizarre. I'm not sure it's a path problem (I would expect a 404).

This is the error I'm getting in the console:

Uncaught SyntaxError: Unexpected token <

And when I view the resource it's picking up for the js file, it's identical to the template. I've placed my js and css relative to the template folder, so I would expect it would find it:

app/
- templates/
- css/
- js/

So my script is called thusly in the template:

<script src="../js/main.js"></script>

How should I be structuring my JS and CSS resources (and later, images, and SASS/LESS)?

Edit

This is what I see in the source for Chrome devtools:

screenshot of devtools

  • 写回答

1条回答 默认 最新

  • duanbei1903 2015-10-27 15:30
    关注

    (╯°□°)╯︵ ┻━┻ Ah it was the app.yaml file. I had:

    application: bedlington
    version: 1
    runtime: go
    api_version: go1
    
    handlers:
    - url: /.*
      script: _go_app
    
    - url: /css
      static_dir: css
    
    - url: /js
      static_dir: js
    

    But that first url handler catches all the things. So instead this solved the problem:

    application: bedlington
    version: 1
    runtime: go
    api_version: go1
    
    handlers:
    - url: /
      script: _go_app
    
    - url: /css
      static_dir: css
    
    - url: /js
      static_dir: js
    

    Now I don't know how to catch all the urls (or how to properly exclude resource folders), but it solves the initial problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度