【问题标题】:Google App engine + HTML + PDF谷歌应用引擎 + HTML + PDF
【发布时间】:2013-06-19 06:40:30
【问题描述】:

我使用 Google App 引擎 + Python +Jinja2 和 MySQL 数据库创建了一个简单的网站。该网站有一个主页 (index.html),使用 Python 代码中的 Jinja2 渲染,数据从 MySQL 数据库加载。

在 index.html 页面上,我创建了一个水平菜单(关于、主页、服务、产品)。

当我单击关于时,我想加载一个新的 HTML 页面(比如 About.html)。同样,当我单击产品时,(我想加载 Products.Html)。这里我想嵌入一个pdf文件。

我不确定如何添加这些额外的 HTML 页面。有人可以建议。

这是我的 App.yaml 文件。

application: ckappnotes
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /stylesheets
  static_dir: stylesheets

- url: .*
  script: stn.app

libraries:
- name:  jinja2
  version:  latest

我已将这些行添加到 App.yaml。

- url: /
  static_files: DTD.html
  upload: DTD.html

- url: /
  static_files: S1.pdf
  upload: S1.pdf

这样做会覆盖我原来的 index.html 页面。

【问题讨论】:

    标签: python google-app-engine pdf


    【解决方案1】:

    您的url 条目必须彼此唯一。正如您所注意到的,您已经用url: / 覆盖了您的主页。相反,您需要为每个页面创建一个 url,如下所示:

    - url: /DTD.html
      static_files: DTD.html
      upload: DTD.html
    
    - url: /S1.pdf
      static_files: S1.pdf
      upload: S1.pdf
    

    如果您只有几个文件,这很好,但您可能想使用Static File Pattern Handler

    - url: /page
      static_dir: page
    

    在本例中,您将 DTD.html 和 S1.pdf 放入名为 page 的新文件夹中。您的index.html 文件会将它们引用为/page/DTD.html/page/S1.pdf。然后,当您要添加第三个文件时,无需更改 app.yaml,只需将它们添加到文件夹并使用相同的 URL 模式即可。

    【讨论】:

      猜你喜欢
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-12
      • 2012-06-19
      • 1970-01-01
      相关资源
      最近更新 更多