【发布时间】:2013-10-07 17:42:37
【问题描述】:
这是我的 main.py 文件和我想要由我正在使用的 Jinja2 模板呈现的 html 文件:
main.py
import os
import webapp2
import jinja2
from google.appengine.ext import db
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape=True)
class Handler(webapp2.RequestHandler):
def write(self, *a, **kw):
self.response.out.write(*a, **kw)
def render_str(self, template, **params):
t = jinja_env.get_template(template)
return t.render(params)
def render(self, template, **kw):
self.write(self.render_str(template, **kw))
class MainPage(Handler):
def get(self):
self.render("temp.html")
app = webapp2.WSGIApplication([('/', MainPage)], debug=True)
temp.html
<!DOCTYPE html>
<html>
<head>
<style>
div#logo
{
position: absolute;
margin-top:5%;
margin-left:25%;
}
div#cart
{
position: absolute;
margin-left:87%;
margin-top:-2px;
}
</style>
</head>
<body>
<div id = logo><img src="logo.png" height = 60% width = 60%></div>
<div id = cart><img src="cart.jpg" height = 75 px ></div>
</body>
</html>
现在,我已将 html 文件与所需的图像一起保存在我的应用引擎应用程序目录的模板文件夹中。此外,当我在浏览器上运行 html 文件时,它可以正常工作。但是,当我使用 GAE 运行我的应用程序时,我得到的只是一个空白屏幕。为什么会这样?为什么我的 html 文件没有被渲染?
【问题讨论】:
-
我希望页面可以显示,但图像没有。您是否真的在 app.yaml 中定义了任何处理程序来显示您的图像?
-
我应该怎么做?
-
也许尝试阅读文档?
-
我在我的目录中创建了一个名为“stylesheets”的文件夹,并将我的 css 文件复制到该文件夹中。然后我在模板文件夹中的 html 文件中使用外部 css 定义链接了这个文件。这是我添加的额外处理程序: - url: /stylesheets static_dir: stylesheets 但是,我仍然得到一个空白屏幕。还能做什么?
标签: python html django google-app-engine