开发者

Is there Django middlware to accept multiple 'requests' in a request and return multiple 'responses' in a response?

开发者 https://www.devze.com 2023-02-22 00:01 出处:网络
I\'m looking for Django middleware to let me issue several queries in one request and combine the [JSON] results to send back in one request? To illustrate:

I'm looking for Django middleware to let me issue several queries in one request and combine the [JSON] results to send back in one request? To illustrate:

If I have two web methods:

/query/show/widgets => ['widget1', 'widget2']

/query/show/sprockets =开发者_开发知识库> ['sprocket1', 'sprocket2']

and I want to do this:

/multiple:/show/widgets;/show/sprockets

which might return something like

{'widgets': ['widget1', 'widget2'],
 'sprockets': ['sprocket1', 'sprocket2']}

I could write this myself but there may already be something that can do the job.


I highly doubt this exists, so you'll pretty much have to do it yourself.

Write a middleware that looks for your separator, split those URLs, resolve them and call the view, then merge the results.

0

精彩评论

暂无评论...
验证码 换一张
取 消