【发布时间】:2013-04-27 09:10:35
【问题描述】:
希望使用 Python 从特定网站获取数据以上传到 Google App Engine。这个想法是创建一个数据库数据来存储服务器上的信息,以便在 Web 应用程序中检索和显示。
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
import os
import datetime
from google.appengine.ext.webapp import template
# A class which creates all the pokemon on the server
class Pokemondata(db.Model):
number = db.IntegerProperty()
pokemonname = db.StringProperty()
description = db.StringProperty()
newpoke = Pokemondata(number="001",pokemonname="Balbasuar",description="The grass pokemon")
newpoke = Pokemondata(number="002",pokemonname="Ivysaur",description="The seed pokemon")
newpoke = Pokemondata(number="003",pokemonname="Venasaur",description="Another grass pokemon")
newpoke.put()
# A class to put new pokemon in to the server ?
class ApplyHandler(webapp.RequestHandler):
def post(self):
self.session = Session()
pnumber = self.request.get('number')
pname = self.request.get('pokemonname')
pdescription = self.request.get('description')
newpoke = Pokemondata(number=pnumber,pokemonname=pname,description=pdescription)
newpoke.put()
self.session['pokemon'] = pname
doRender(self,"board.htm",{})
# Construct a google table for this data
# to display
class JSONInterface(webapp.RequestHandler):
def get(self):
que = db.Query(Pokemondata)
listing = que.fetch(limit = 12)
doRender(self,'http://pokedexapp.appspot.com/?user=cater54321@gmail.com#input',
{'listing':listing})
application = webapp.WSGIApplication([('/(.*html)?', ApplyHandler),
('/json', JSONInterface)], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
当我部署应用程序进行测试时,我收到了服务器错误。谁能告诉我这是否是朝着正确方向迈出的一步以及需要修改什么?
当前的yaml文件是
应用程序:pokedexapp 版本:1 运行时:蟒蛇 api_version: 1
处理程序: - 网址:/.* 脚本:main.py
【问题讨论】:
-
我理解代码缩进是错误的。我目前正在尝试修复它
-
您想发布您遇到的错误。
-
你能发布 .yaml 文件吗?我在这里看到一些错误,您在处理程序中使用的 MainHandler、JSONInterface、SearchResult 类在哪里?
-
我对代码做了一些修改并添加了yaml文件的内容。
标签: python database google-app-engine web-applications