我有一个主页,它有一个GET
和一个POST
功能。该POST
函数从搜索屏幕获取数据,并应通过 ajax 调用将此信息传递给worldMarkers
类。这是单独的,因为应用程序的其他方面将需要它。
这样做的目的是让用户在通话index
期间按下提交POST
,它能够限制检索到的结果。这个逻辑存在于worldMarkers
类中。
class index(object):
def GET(self):
# do things to generate the page
return html
def POST(self):
continents = web.input(search_continents=[])
countries = web.input(search_countries=[])
searchDict = {}
if continents['search_continents']:
searchDict['continents'] = continents['search_continents']
if countries['search_countries']:
searchDict['countries'] = countries['search_countries']
markers = worldMarkers()
# Yes, this just spits out the results, nothing fancy right now
return markers.GET()
#alternatively,
#return markers.GET(searchDict)
class worldMarkers(object):
def __init__(self, **kargs):
self.searchDict = None
if 'searchDict' in kargs:
self.searchDict = kargs['searchDict']
def GET(self):
print "SearchDict: %s" % (self.searchDict)
# No searchDict data exists
第一个选项,没有参数 tomarkers.GET()
意味着我的搜索条件都没有通过。如果我这样做markers.GET(searchDict)
,我会收到此错误:
<type 'exceptions.TypeError'> at /
GET() takes exactly 1 argument (2 given)
如何将搜索参数传递给worldMarkers
类?