Python 如何将聚合物项目引入谷歌应用程序引擎
我有谷歌应用程序引擎应用程序,我想把聚合物组件。我认为最好的开始方式是将这个应用程序引入谷歌应用程序引擎 所以我用GoogleAppEngineLauncher创建了我的新GoogleAppEngine应用程序。然后我在谷歌应用程序引擎上创建了我的应用程序 此测试应用程序的URL为 于是我把这个聚合物项目移到了我的文件夹中,并上传到了谷歌应用引擎 应用程序在显示 你好,世界 文本 于是我找到了一篇文章,告诉我接下来的一些步骤,但我遗漏了一些东西。邮报 在文章Mike中,作者给了我main.py的代码,我通过删除以下内容对其进行了修改Python 如何将聚合物项目引入谷歌应用程序引擎,python,google-app-engine,polymer,Python,Google App Engine,Polymer,我有谷歌应用程序引擎应用程序,我想把聚合物组件。我认为最好的开始方式是将这个应用程序引入谷歌应用程序引擎 所以我用GoogleAppEngineLauncher创建了我的新GoogleAppEngine应用程序。然后我在谷歌应用程序引擎上创建了我的应用程序 此测试应用程序的URL为 于是我把这个聚合物项目移到了我的文件夹中,并上传到了谷歌应用引擎 应用程序在显示 你好,世界 文本 于是我找到了一篇文章,告诉我接下来的一些步骤,但我遗漏了一些东西。邮报 在文章Mike中,作者给了我main.py的
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello world!')
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
然后我将迈克的代码粘贴到文件中
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秒后重试
我希望有人能让我走,因为我肯定想玩其中的一些组件
问候,
Chris对于初学者,您需要在
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
- url: .*
script: main.py
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)
现在,您的问题似乎是将python27的app.yaml声明与python25应用程序的代码混合在一起。对于旧版本,处理程序声明如下所示:
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
- url: .*
script: main.py
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)
请注意,声明的脚本是如何由服务器执行的实际python文件
现在,在框架的最新推荐版本中,您的应用程序代码应该如下所示:
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
- url: .*
script: main.py
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声明拾取它的(在您的情况下,它在main
模块中查找app
对象)
杰米·戈麦斯再次感谢你的帮助。 我能够做到这一点,并想与大家分享我是如何做到的,以防其他人也有同样的兴趣
关于V2
关于我们的申请
链接
Jamime,谢谢您提供的信息。我现在正在处理导入webapp2代码。你寄来的其他东西真的很快就收到了。我必须标记threadsafe=no。我希望很快带着一条成功的消息回到这里。尊敬的克里斯,我在这方面没有任何运气,所以我想问另一个问题,目的是简化事情。我希望这个问题的答案最终能帮助我在这里获得成功。