使用Eve中的事件钩子时出现内部服务器错误
我想在每次进行POST请求时触发一个事件。这是我的代码:
from eve import Eve
def before_insert(response):
print 'About to return artists'
app = Eve(settings='settings.py')
app.on_insert += before_insert
if __name__ == '__main__':
app.run()
在设置文件里我没有任何代码来处理这些事件——就只是一些标准的东西,当我去掉这一行时: app.on_insert += before_insert,程序运行得很好。
当我进行POST请求时,我得到的是:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>
而当我对这个资源进行GET请求时,我能获取到数据,但POST请求的数据却没有被添加进来……
这是怎么回事??
1 个回答
1
看起来你的回调函数的写法有点问题。试试下面的代码。
from eve import Eve
def before_insert(resource_name, items):
print 'About to return artists'
app = Eve(settings='settings.py')
app.on_insert += before_insert
if __name__ == '__main__':
app.run(debug=True)
无论如何,试着在你的设置文件里把 DEBUG = True
打开,或者用 app.run(debug=True)
来运行你的应用,这样你就能得到一些关于实际问题的提示。