问题
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.
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 ()
回答1:
Add the following to your app.yaml
:
handlers:
- url: /components
static_dir: components
- url: /images
static_dir: images
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
I will also recommend using the webapp2 framework instead, it's recommended for new applications and way better!
来源:https://stackoverflow.com/questions/25246008/relative-paths-to-file-issue-in-deploying-an-app