【发布时间】:2014-11-15 19:08:43
【问题描述】:
我想在 Django 1.7 的表单中使用 typeahead.js。此外,我想使用基于类的视图来实现它。
据我了解问题,我需要创建一个视图,为来自 typeahead.js 的 ajax 请求生成 JSON 响应。
为此使用 django-braces 是个好主意吗?
到目前为止,我所拥有的是:
from braces.views import JSONResponseMixin
[...]
class TagList(JSONResponseMixin, ListView):
"""
List Tags
"""
model = Tag
context_object_name = 'tags'
def get(self, request, *args, **kwargs):
objs = self.object_list()
context_dict = {
"name": <do something with "obs" to get just the name fields>
"color": <do something with "obs" to get just the color fields>
}
return self.render_json_response(context_dict)
这就是我现在卡住的地方。我在正确的道路上吗?或者甚至可以(并且很容易)在没有第三方应用的情况下使用?
【问题讨论】:
标签: python ajax json django typeahead.js