部署应用时文件问题的相对路径 [英] Relative paths to file issue in deploying an app

查看:110
本文介绍了部署应用时文件问题的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个聚合物应用,我正在部署到Google App Engine。这是初学者聚合物教程的第二步。我一直在为某些资源收到404和500错误,特别是这些错误:

I have a polymer app that I'm deploying to Google App Engine. It is step-2 of the beginner polymer tutorial. I keep getting 404s and 500 errors for some resources, specifically these are the errors:

GET http://polymer-test-nik.appspot.com/images/avatar-07.svg 404 (Not Found) polymer-test-nik.appspot.com/:66
GET http://polymer-test-nik.appspot.com/components/core-header-panel/core-header-panel.html 500 (Internal Server Error) polymer-test-nik.appspot.com/:10
GET http://polymer-test-nik.appspot.com/images/avatar-07.svg 404 (Not Found) polymer-test-nik.appspot.com/:66
GET http://polymer-test-nik.appspot.com/components/core-selector/core-selector.html 500 (Internal Server Error) polymer-test-nik.appspot.com/:78

本教程中的目录结构不变。

The directory structure is unchanged from the tutorial.

我使用简单的main.py来为应用程序提供服务

I'm using a simple main.py to serve the app

import random
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:
        i = random.randint(1,11)
        q = 'step-2/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, {}))

class GuideHandler(webapp.RequestHandler):
  def get (self, q):
    q = 'icgt-registration-guide.pdf'
    path = os.path.join (os.path.dirname (__file__), q)
    self.response.headers ['Content-Type'] = 'application/pdf'
    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 ()


推荐答案

您的 app.yaml

handlers:
- url: /components
  static_dir: components
- url: /images
  static_dir: images

值得注意的是,这些处理程序应该在你的 url:。* 声明之后添加,否则它将捕获所有的永远不要再下去了,所以在这个简单的例子中,完整的声明如下所示:

It's worth noting that these handlers should be added after your url: .* declaration, otherwise it will catch all and never go further down, so in this simple example, the complete declaration will look like this:

handlers:
- url: /components
  static_dir: components
- url: /images
  static_dir: images
- url: .*
  script: main.py

我也建议您使用 webapp2 framework ,建议用于新的应用程序和更好的方式!

I will also recommend using the webapp2 framework instead, it's recommended for new applications and way better!

这篇关于部署应用时文件问题的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆