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.

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

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)