缺少静态文件 [英] Static files are missing

查看:21
本文介绍了缺少静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中有一个 /static 文件夹,其中包含应用程序所需的所有静态资源.这是我的静态资源处理程序:

In my app there is a /static folder which contains all the static resources needed by the app. Here is my handlers for the static resources:

- url: /static
  static_dir: static

这直接适用于 /static 中的文件,但假设我还有另一个包含 jQuery 的文件夹:

This works for files directly in /static, but let's say I also have another folder containing jQuery:

static
  |- jquery
  |   - jquery.js
  |
  - images
      - ...
    

当我尝试访问 [myapp].appspot.com/static/jquery/jquery.js 时,它会返回 404,我不知道为什么.

When I try to reach [myapp].appspot.com/static/jquery/jquery.js it would return a 404 and I have no idea why.

还有我的一些文件,包括 .css.ttf 等,给我一个 Could not guess mimtype 错误.我不知道如何解决这个问题.

Also some of my files including .css and .ttf etc. are giving me a Could not guess mimtype error. I have no idea how to solve that.

添加了我的(新)app.yaml.我没有 dispatch.yaml.

Added my (new) app.yaml. I don't have a dispatch.yaml.

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

handlers:
- url: /static/pages_style
  mime_type: text/css
  static_dir: /static/pages_style

- url: /static/images/(.*.(gif|png|jpg))$
  static_files: static/images/1
  upload: static/images/.*.(gif|png|jpg)$

- url: /static/bootstrap 3.3.5
  static_dir: /static/bootstrap 3.3.5

- url: /static/jquery 2.1.4
  static_dir: /static/jquery 2.1.4
    
- url: /.*
  script: myapp.app

libraries:
- name: webapp2
  version: latest
- name: jinja2
  version: latest

推荐答案

[myapp].appspot.com/static/jquery/jquery.js 上的 404 错误请求是由 static_files URL 模式在 static_dir URL 路径下引起的:​​

The 404 errors on [myapp].appspot.com/static/jquery/jquery.js requests were caused by a static_files URL pattern being under a static_dir URL path:

- url: /static/(.*.css)$
  static_files: static/1
  upload: static/(.*.css)$

- url: /static
  static_dir: static

在上面的例子中 /static/(.*.css)$ 匹配位于 /static 下.我猜在这种情况下,GAE 基础设施中的静态目录/文件路由会变得混乱.

In the above example /static/(.*.css)$ matches are located under /static. I guess the static dir/files routing in the GAE infra gets confused in such cases.

解决方案是使路径更加具体,以便 static_dir URL 永远不会包含匹配 static_files URL 模式或其他 static_dir URL 的路径.

The solution is to make the paths more specific such that the static_dir URLs never include paths matching static_files URL patterns or other static_dir URLs.

关于 Could not guess mimetype 错误,这个问答很好地解释了它:无法猜测 mimetype

About the Could not guess mimetype error, this Q&A explains it well: Could not guess mimetype

这篇关于缺少静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆