How to bring a Polymer project to Google App Engine

I have a Google App Engine application in which I would like to bring Polymer components. I thought the best way to get started is to bring the initial project to the Google App Engine, so I created a new Google App Engine application using the Google App Engine Launcher. Then I created my application in Google App Engine.

URL of this test application: http://polymertvshelp.appspot.com/

So, I moved the Polymer project to my folder and uploaded it to the Google App Engine

The app lands on a page that displays

Hello World!

text.

So, I find a message that talks about the next steps, but I'm missing something. Post URL

In Mike's post, the author gave me the code for main.py, which I changed by deleting the following

import webapp2

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.response.write('Hello world!')

app = webapp2.WSGIApplication([
    ('/', MainHandler)
], debug=True)

Then I put Mike's code in the file

 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 ()

this is the only code that is now executed in this main.py file

I also modified the app.yaml file to look like

application: polymerxxxx
version: 2
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: .*
  script: main.app

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

I also changed index.html in the step-2 folder, deleting .. before the relative paths.

When I run the application, I now get a 500 server error

Error: server error

The server detected an error and could not fulfill your request. Try again after 30 seconds.

I hope someone can make me go because I really would like to play with some of these components.

Hi,

Chris

+4
source share
2 answers

. , , , - .

  • Google App Engine - python sdk
  • "components" ""
  • "" " ", - Google ( "" ).
  • ( , ) . .
  • 'about_v2.html',

<!DOCTYPE html>
<html>
  <head>
    <title>About V2</title>
  </head>
  <body>
 
<H1>About Our Application</H1>
<br /><br />
<p><a href="components/paper-radio-group/demo.html" target="_blank">Paper Radio Group Demo</a></p>
<hr>
<H3>Links</H3>
    <a href="/">Home</a><br/>
  </body>
</html>
Hide result
  1. app.yaml

    application: hellopolymer
    version: 2
    runtime: python27
    api_version: 1
    threadsafe: yes

    handlers:
    - url: /favicon\.ico
      static_files: favicon.ico
      upload: favicon\.ico
    - url: /components
      static_dir: components
    - url: .*
      script: main.app

    libraries:
    - name: webapp2
      version: latest
    - name: jinja2
      version: latest
Hide result
  1. "main.py"

import os
import webapp2
import jinja2

env = jinja2.Environment(
  loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), 'templates')))

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.response.write('Hello world! <a href="/about_v2.html">About</a>.<br />')
       
class AboutPage_v2(webapp2.RequestHandler):
    def get(self):
        template_values = {
            
        }

        template = env.get_template('about_v2.html')
        self.response.out.write(template.render(template_values))


app = webapp2.WSGIApplication([
    ('/', MainHandler),
    ('/about_v2.html', AboutPage_v2)],

                              debug=True)
Hide result
  1. , .

. appspot.com, , , .

... Apppot Polymer.

+2

URL url: .*, , app.yaml :

application: polymerxxxx
version: 2
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico
- url: /components
  static_dir: components
- url: /images
  static_dir: images
- url: .*
  script: main.app

, app.yaml python27 python25, :

- url: .*
  script: main.py

, script python, .

, , :

import webapp2

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hello, World!')

app = webapp2.WSGIApplication([
    ('/', MainPage),
], debug=True)

, , , app.yaml( , app main).

...

+2

All Articles