【问题标题】:Why is my HTML page not being displayed on the local host in Google App Engine?为什么我的 HTML 页面没有显示在 Google App Engine 的本地主机上?
【发布时间】: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


【解决方案1】:

一些建议:

  1. 检查您的 html 是否实际呈现(在 html 文件中放入一些文本)
  2. 您的 app.yaml 文件需要包含放置照片的静态目录。有关示例,请参阅 https://github.com/GoogleCloudPlatform/appengine-guestbook-python/blob/master/app.yaml
  3. 使用适合您放置图像位置的 URL 引用图像,例如 如果您将它们放在“客户端”目录下。

https://github.com/GoogleCloudPlatform/appengine-guestbook-python

基本配置不错。

【讨论】:

    猜你喜欢
    • 2011-11-10
    • 2012-07-12
    • 1970-01-01
    • 2020-12-12
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 2022-11-16
    • 1970-01-01
    相关资源
    最近更新 更多