【问题标题】:Root html (/index.html) can't be fetched. Returns 404无法获取根 html (/index.html)。返回 404
【发布时间】:2011-10-09 15:27:43
【问题描述】:

目录结构是-

MyApplication (Project Dir)

-static
   --inside static, I got different dirs containing images, css, htmls, etc
-some other dirs
-app.yaml
-index.py
-index.html

app.yaml的内容是-

application: MyApplicationID
version: 1
runtime: python
api_version: 1

handlers:

- url: /favicon.ico
  static_files: static/images/favicon.ico
  upload: static/images/favicon.ico
  mime_type: image/x-icon

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

- url: /static
  static_dir: static  
  secure: optional

- url: /projects
  static_dir: projects  
  secure: optional

- url: /about
  static_dir: about  
  secure: optional

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

- url: /.*
  script: index.py
  secure: optional

一切正常,除了如果 html 页面上的任何内容被重定向到“index.html”,我会发现找不到页面(“GET /index.html HTTP/1.1”404 -)错误.我试着跟随这个 - https://gist.github.com/873098 但仍然没有运气。我在其他线程上尝试了其他建议,但仍然没有运气。如果我删除 - url: / 仍然没有运气。请指教。

【问题讨论】:

    标签: python google-app-engine http-status-code-404


    【解决方案1】:

    对方说的没错,你没有urlindex.html的入口,点赞

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

    编辑 2:为了清楚起见,无论 static_files 行上有什么内容,即使 static_files 行包含子目录,这仍然会导致 URL 为 http://mysite.com/index.html

    【讨论】:

    • 没用,我不想拥有像 myURL.com/some_dir/index.html 这样的目录
    • 你误会了!您计算机上的目录与用于检索它的目录无关。这是 ` - url: ` 行上的内容。
    • 只是为了让你知道,目录不是必需的。你只需要从脚本中处理它。 application = webapp.WSGIApplication( [ ('/', MainPage), ('/index.html', MainPage) ], debug=True)
    【解决方案2】:

    根据 app.yaml 的内容,对“/index.html”的请求将由 index.py 处理。大概您在该文件中没有“/index.html”的处理程序。

    如果您希望 index.html 为“/index.html”的请求提供服务,请添加与 URL 匹配的 app.yaml 映射(或者,只需重定向到“/”而不是“/index.html”该网站,它不那么丑陋)

    【讨论】:

    • 我愿意。 def render(self,template_file,template_value): path=os.path.join(os.path.dirname(file),template_file) self.response.out.write(template.render(path,模板值))
    • def get(self): self.render('index.html', {})
    猜你喜欢
    • 2015-11-21
    • 2021-02-11
    • 2021-12-26
    • 1970-01-01
    • 2020-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多