【发布时间】:2014-01-09 21:11:28
【问题描述】:
这是一个初学者的问题。我无法让我的 css 在 Google App Engine 中工作。
我的 YAML 文件有以下内容
application: helloworld27dec
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /stylesheets/
static_dir: stylesheets
- url: /.*
script: helloworld.application
我的 python 脚本 (helloworld.py) 有以下代码:
import webapp2, cgi, re, datetime
class MainPage(webapp2.RequestHandler):
def render(self,htmlfile):
with open(htmlfile, 'r') as content_file:
if (content_file):
content = content_file.read()
return content
def get(self):
self.response.write(self.render('test2.html'))
application = webapp2.WSGIApplication([('/', MainPage)], debug=True)
我的html文件(test2.html)如下:
<!doctype HTML>
<html>
<head>
<meta charset="utf-8">
<title> My Title </title>
<link type="text/css" rel="stylesheet" href="/stylesheets/style.css" />
</head>
<body>
<h1> Hello World!</h1>
</body>
</html>
我的css(style.css)在/stylesheets文件夹下,如下:
<style>
h1{
color: red;
background: yellow;
}
</style>
我看不到 css 工作(即红色字体和黄色背景)。我尝试了很多事情,但看起来我犯了一些非常根本的错误。
这是我在日志文件中得到的
INFO 2014-01-09 18:09:30,532 module.py:617] 默认值:“GET /stylesheets/style.css HTTP/1.1”304 -
我将非常感谢一些帮助/澄清我在这里犯了什么错误。
【问题讨论】:
-
似乎没有什么问题:304 is Not Modified,也就是说你将使用缓存版本。
-
尝试将
default_expiration: "0d 0h 1m"添加到您的 app.yaml 以减少缓存时间。不过要注意它对生产的影响 -
谢谢吉米。我尝试添加 default_expiration:“0d 0h 1m”。仍然无法让 css 正常工作。令人沮丧,因为如果我将 css 内联放在标题中,它看起来很简单并且有效。
标签: python html css google-app-engine