静态文件丢失 [英] Static files are missing

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

问题描述

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

   -  url:/ static 
static_dir:static

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

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

当我尝试以达到 [myapp] .appspot.com / static / jquery / jquery.js 它会返回404,我不知道为什么。



我的一些文件包括 .css .ttf 等都给了我一个无法猜测mimtype 错误。我不知道如何解决这个问题。






编辑



添加了我的(新)app.yaml。

 版本:1 
运行时:python27
api_version: 1
threadsafe:true

处理程序:
- 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

库:
- 名称:webapp2
版本:latest
- name:jinja2
版本:latest


解决方案<$ c $ <> code> c> [myapp] .appspot.com / static / jquery / jquery.js 请求是由 static_files URL模式低于 static_dir 网址路径:

   -  url:/static/(.*\.css)$ 
static_files:static / \ 1
上传:static /(.* \.css)$

- url:/ static
static_dir:static

在上面的例子中, / static /(.* \.css)$ 匹配位于 /静态。我猜在这种情况下,GAE中的静态目录/文件路由会感到困惑。



解决方案是使路径更具体,使得 static_dir URL不会包含匹配 static_files URL模式或其他 static_dir URL的路径。



关于无法猜测mimetype 错误,这个问题解答很好:不能猜测mimetype


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

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

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

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

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.


Edit

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

解决方案

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

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.

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.

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

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

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