我有Google App Engine应用程序,我想将Polymer组件带入。我认为最好的方法是将initial Project引入Google App Engine 所以我使用Google App Engine Launcher创建了我的新Google App Engine应用程序。然后我在Google App Engine上创建了我的应用程序。
此测试应用的网址为http://polymertvshelp.appspot.com/
然后我将Polymer项目移动到我的文件夹中并将其上传到Google App Engine
应用程序在显示
的页面上着陆Hello world!
文本。
然后我发现一篇帖子告诉我接下来的一些步骤,但我遗漏了一些东西。邮政URL
在Mike的帖子中,作者通过删除以下
给了我修改的main.py的代码import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello world!')
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
然后我将Mike的代码粘贴到文件
中 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 ()
这是现在在这个main.py文件中执行的唯一代码
我还修改了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: .*
script: main.app
- url: /components
static_dir: components
- url: /images
static_dir: images
我还通过删除相对路径前面的..修改了step-2文件夹中的index.html。
当我运行应用程序时,我现在得到了 500服务器错误
错误:服务器错误
服务器遇到错误,无法完成您的请求。 请在30秒后再试一次。
我希望有人能帮助我,因为我肯定会想要使用其中一些组件。
此致
克里斯
答案 0 :(得分:2)
对于初学者,您需要在 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
现在,您的问题似乎是您正在将 python27 的 app.yaml 声明与 python25 应用的代码混合在一起。对于旧版本,您的处理程序声明将如下所示:
- url: .*
script: main.py
注意声明的脚本是如何实际的 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
对象{1}}模块)。
答案 1 :(得分:2)
<!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>
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
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)
注意:当我将此测试应用程序加载到appspot.com时,我注意到聚合物页面在我的计算机上工作正常但不适用于我的移动设备。
我的猜测...... Appspot还没有为Polymer做好准备。