我有一个资源,例如ABC,我想操纵另一个资源,例如BCD,当某些条件满足而我向ABC发布一个新项目时,我知道我可以挂钩事件post / pre_POST_ABC但是有一个'内部'方式在没有再通过HTTP的情况下在BCD上发帖?
In your callback function you could either:
A) use the data driver to store data directly to the database
Something like this:
def update_ABC(request, payload):
accounts = app.data.driver.db['abc_collection']
account = accounts.insert(docs)
app = Eve()
app.on_post_POST_ABC += update_ABC
app.run()
Would do the trick. You would be bypassing the framework this way, and storing directly on the database.
B) Use app.test_client.post()
to POST through directly through the application.
app.test_client().post('/bcd', json.dumps({"field":"value"}, content_type='application_json'))
This is probably a better option since the request goes through the framework (meta fields like data_created
are handled for you.)
Update : With v0.5+ you can now use post_internal
to achieve the same result. There are equivalent internal methods available for other CRUD methods as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.