【问题标题】:Google App Engine: Serve static webpage in a subdirectoryGoogle App Engine:在子目录中提供静态网页
【发布时间】:2015-03-21 21:50:19
【问题描述】:

我的文件结构:
根目录:
css [目录]
js [目录]
img [目录]
字体 [目录]
khikhi [目录]
应用程序.yaml
index.html
index.yaml

khikhi 目录:
css [目录]
js [目录]
img [目录]
index.html

App.yaml:

application: mywebsitesname
version: 1
runtime: python
api_version: 1

handlers:
- url: /(.*\.(svg|ttf|woff|woff2|gif|png|jpg|ico|js|css|eot))
  static_files: \1
  upload: (.*\.(svg|ttf|woff|woff2|gif|png|jpg|ico|js|css|eot))

- url: /robots.txt
  static_files: robots.txt
  upload: robots.txt 

- url: /.*
  script: main.py    

Main.py:

# Copyright 2012 Digital Inspiration
# http://www.labnol.org/

import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template

class MainHandler(webapp.RequestHandler):
  def get (self, q):
    if q is None:
      q = 'index.html'
    path = os.path.join (os.path.dirname (__file__), q)
    self.response.headers ['Content-Type'] = 'text/html'
    self.response.out.write (template.render (path, {}))

def main ():
  application = webapp.WSGIApplication ([('/(.*html)?', MainHandler)], debug=True)
  util.run_wsgi_app (application)

if __name__ == '__main__':
  main ()

目前,当我转到 mydomain.com 时,正在提供我根目录中的 index.html,但我希望在我转到 mydomain.com/khikhi/ 或 mydomain 时也提供 /khikhi/index.html .com/khikhi。我应该对文件进行哪些更改才能使其正常工作?

【问题讨论】:

    标签: python google-app-engine


    【解决方案1】:

    只需添加,作为handlers:...下方的第一个条目:

    - url: /khihi
      static_files: khikhi/index.html
    

    整个安排可能还有其他问题,例如很难理解您的意思

    当我访问 mydomain.com/khikhi 或 mydomain.com/khikhi

    “当我去某事或完全相同的事情时”-在这种情况下,您的是什么意思,祈祷?!但是,我只是想直接回答你的直接问题(所以我将“A 或 A”等同于“A”,就像在正常逻辑或任何编程语言中一样——即使 Gricean 暗示分析 [*] 表明您的 Q 一定在那一点上有问题!-)。

    [*] 语用学 的核心基础,作为语言学的一个关键部分,以 H. P. Grice 命名,是指根据 Grice 的“格言”在话语中暗示但并未实际表达的意思-- 例如,“我从不在 SO 海报上诅咒在周末提出模棱两可的问题”这句话实际上是正确的,并且 不是 暗示我可能在工作日实际上诅咒他们 -- 但 Gricean 的暗示我真的可以吗,否则,我为什么要通过“周末”限制来限定非诅咒断言?-)

    【讨论】:

    • 很抱歉,忘记在其中一个链接上添加斜线。我得到一个“缺少 URL“/khikhi”的“上传”属性。当我尝试运行它时出错。因此,我向处理程序添加了“上传:khikhi/index.html”属性。当我转到 mydomain.com/khikhi/ 时,它也不起作用。我的 khikhi/css、khikhi/js 和 khikhi/img 中的所有文件都没有被加载。
    • 修复了所有问题。将链接标签更改为绝对路径,在 app.yaml 文件中添加了一些其他内容!谢谢! :)
    • @UmangGalaiya,不客气!希望我能得到你的接受(点击我的答案左侧的复选标记形状的轮廓......!-)
    猜你喜欢
    • 1970-01-01
    • 2017-10-06
    • 2017-08-15
    • 2012-02-02
    • 2016-01-22
    • 2015-05-28
    • 1970-01-01
    • 2019-05-19
    • 2016-09-02
    相关资源
    最近更新 更多