Django 客户端查询构建
我正在制作一个非常标准的 AJAXy(实际上没有 XML)网页。浏览器会发出一堆 API 查询,这些查询返回 JSON 来运行网站。问题是,每次页面需要做新的事情时,我都需要添加到API接口。新的 API 接口通常只不过是数据库查询,然后将返回的对象映射到 JSON。
我想做的是摆脱所有服务器端重复,只让页面本身发出数据库请求(使用模型接口),但以安全的方式(即仅只读)。我认为这相当于一个使用 JSON 或类似的东西构造 Q 对象的接口,然后将其发送到服务器,运行查询并返回结果。在我为此创建自己的半残架构之前,我想知道这是否已经做得很好。另外,这是否是消除这种重复的最佳方法?
谢谢
I'm making a pretty standard AJAXy (well, no XML actually) web page. The browser makes a bunch of API queries that return JSON to run the site. The problem is, I need to add to the API interface each time the page needs to do something new. The new API interface is usually little more than a database query followed by mapping the returned objects to JSON.
What I'd like to do is to get rid of all that server-side duplication and just have the page make database requests itself (using the model interface), but in a way that is safe (i.e. just read only ones). I think this would amount to an interface for constructing Q
objects using JSON or something like that, and then send that up to the server, run the query, and return the results. Before I go making my own half-broken architecture for this, I'm wondering if this has already been done well. Also, is this even the best way to go about eliminating this duplication?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在没有第3方应用程序的情况下搜索 django 模型的多个字段
Django SQL 或通过 filter() & Q(): 动态?
生成一个基于 django 查询集dict 键
只需在适当的情况下替换为
operator.and_
即可。Search multiple fields of django model without 3rd party app
Django SQL OR via filter() & Q(): Dynamic?
Generate a django queryset based on dict keys
Just replace with
operator.and_
where appropriate.