【问题标题】:App Engine can't find static filesApp Engine 找不到静态文件
【发布时间】:2013-09-23 13:34:59
【问题描述】:

我在我的应用引擎应用程序上使用 webapp2 和 python 2.7。但是,我在 app.yaml 上的网址有问题。

我的静态文件位于路径根目录的static/ 目录中。所以在static/里面我有static/scripts/MyScript.js

当我将 app.yaml 设置为:

application: myapp
version: 1
runtime: python27
threadsafe: true
api_version: 1

handlers:
- url: /.*
  script: myapp.app

- url: /static
  static_dir: static

libraries:
- name: webapp2
  version: latest

在我的 HTML 代码中,js 的调用如下: <script src="static/scripts/Fuel.js"></script>

但是,文件没有加载,我得到一个 404 错误。 (.css 文件也会出现这个问题。

但是,如果我将 app.yaml 中的第一个 url 更改为:

handlers:
- url: /
  script: myapp.app

静态文件已加载,但是当我尝试在我的应用程序中调用路由 url 时,例如我在表单中调用的 url 以将一些数据保存在服务器上,找不到该路由并且我也收到 404 错误。

这是我在 myapp.py 文件中的路由代码。

app = webapp2.WSGIApplication(
                              [('/', MainHandler),
                              ('/save', SaveData),], 
                              debug=True)

所以如果我尝试访问 myapp.appspot.com/save,它会返回 404 错误,说:

在此服务器上找不到请求的 URL /save。

有什么想法吗?如果您需要有关它的更多信息,请在 cmets 上询问。

谢谢。

【问题讨论】:

    标签: google-app-engine python-2.7 webapp2


    【解决方案1】:

    将您的全部捕获网址 /.* 放在底部,因为这是按顺序评估的。这意味着它永远不会过去。

    handlers:
    - url: /static
      static_dir: static
    
    - url: /.*
      script: myapp.app
    

    【讨论】:

      猜你喜欢
      • 2017-08-15
      • 1970-01-01
      • 2015-03-02
      • 2011-07-18
      • 1970-01-01
      • 1970-01-01
      • 2021-02-03
      • 1970-01-01
      • 2011-05-09
      相关资源
      最近更新 更多