我的 Python Pyramid 项目中通过 add_handler 添加了几个视图类:
config.add_handler('export_index', '/export', handler=ExportViews, action='index')
class ExportViews(ConfigViewBase):
@action(request_method='POST', name='index',
request_param='ftp_export.form.submitted')
@action(request_method='POST', name='index', xhr=True, renderer='json',
request_param='ftp_export.form.submitted')
def ftp_export(self):
#process form
return {}
@action(request_method='GET')
def index(self):
return {}
是否可以做同样的事情:
config.add_handler('export_index', '/export', handler=ExportViews)
class ExportViews(ConfigViewBase):
@action(request_method='POST',
request_param='ftp_export.form.submitted')
@action(request_method='POST', xhr=True, renderer='json',
request_param='ftp_export.form.submitted')
def ftp_export(self):
#process form
return {}
@action(request_method='GET')
def __call__(self):
return {}
所以当浏览器获取页面时调用了 __call__ ,当我在同一页面上发布表单时应该调用 ftp_export 。现在我明白了page not found error
谢谢你。