在GAE中,我收到一个错误告诉我:
TypeError:get_default_tile()只取1个参数(给定2个)
正如您所看到的,我的主要文件 get_default_tile()中的代码只传递了一个 name 的参数:
default_tile = self.get_default_tile(name)
完整的代码如下:
import jinja2 # html template libary
import os
jinja_environment = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
import urllib
import urllib2
import webapp2
from google.appengine.ext import db
from google.appengine.api import urlfetch
class Default_tiles(db.Model):
name = db.StringProperty()
image = db.BlobProperty(default=None)
class MainPage(webapp2.RequestHandler):
def get(self):
# this just prints out the url which the user enters into input
image_name = self.request.get('image_name')
template_values = {
'image_name': image_name,
}
template = jinja_environment.get_template('index.html')
self.response.out.write(template.render(template_values))
class Upload(webapp2.RequestHandler):
def post(self):
# get information from form post upload
image_url = self.request.get('image_url')
image_name = self.request.get('image_name')
# create database entry for uploaded image
default_tile = Default_tiles()
default_tile.name = image_name
default_tile.image = db.Blob(urlfetch.Fetch(image_url).content)
default_tile.put()
self.redirect('/?' + urllib.urlencode({'image_name': image_name}))
class Get_default_tile(webapp2.RequestHandler):
def get(self):
name = self.request.get('image_name')
default_tile = self.get_default_tile(name)
self.response.headers['Content-Type'] = "image/png"
self.response.out.write(default_tile.image)
def get_default_tile(name):
result = db.GqlQuery("SELECT * FROM Default_tiles WHERE name = :1 LIMIT 1", name).fetch(1)
if (len(result) > 0):
return result[0]
else:
return None
app = webapp2.WSGIApplication([('/', MainPage),
('/upload', Upload),
('/default_tile_img', Get_default_tile)],
debug=True)
任何帮助将不胜感激。
答案 0 :(得分:6)
get_default_tile():
是类Get_default_tile
的成员方法,因此您需要像这样定义它:
def get_default_tile(self, name):
或者如果您希望它是静态方法:
@staticmethod
def get_default_tile(name):
答案 1 :(得分:0)
class myclassname(webapp2.RequestHandler):
def get(self): self.response.write('hola')
我用=
解决了class myclassname(webapp2.RequestHandler):
def get(self, **name**): self.response.write('hola')