我将一个 CSS 文件作为静态文件添加到我的元素中只是为了尝试它是如何工作的,但我从一开始就失败了。
CSS 文件是:
body {
background:#00FF00;
}
我配置的 app.yaml 文件是;
application: s~my_app_id
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /stylesheets
static_dir: stylesheets
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /.*
script: main.app
- url: /remote_api
script: google.appengine.ext.remote_api.handler.application
login: admin
libraries:
- name: webapp2
version: 2.5.1
- name: jinja2
version: latest
builtins:
- remote_api: on
在本地或者我部署后都不行,而我在main.py中的页面内容是;
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheets/main.css"/>
</head>
<body>
some stuff
</body>
</html>
以及我的页面内容在浏览器中的情况;
<html>
<head>
<style type="text/css"></style>
</head>
<body>
some stuff
</body>
</html>
我没有收到任何错误或日志,一切看起来都很完美。我尝试在 chrome 和 ie10 中显示这个
最佳答案
我认为你应该尝试在你的 app.yaml 中声明它:
application: my-gae-app
version: 2013
runtime: python27
api_version: 1
threadsafe: true
default_expiration: "14d 5h"
handlers:
- url: /css
static_dir: css
如果像上面那样声明,CSS 将会加载。您还必须在 HTML 中正确加载它:
<link href="/css/index.css" rel="stylesheet" type="text/css">
关于html - CSS 文件未加载 GAE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18722648/