「JQuery UI のAutocompleteをDjangoで実装」の版間の差分
ナビゲーションに移動
検索に移動
| (同じ利用者による、間の1版が非表示) | |||
| 1行目: | 1行目: | ||
| − | ==jQuery UI のAutocompleteをDjangoで実装== | + | ==[[jQuery UI のAutocompleteをDjangoで実装]]== |
| − | [[jQuery]][[Django]] | + | [[jQuery]] | [[Django]] | |
| − | === | + | ===[[jQuery]]側=== |
$("#txt_tag").autocomplete({ | $("#txt_tag").autocomplete({ | ||
delay: 500, | delay: 500, | ||
| 8行目: | 8行目: | ||
}); | }); | ||
| − | === | + | ===[[Django]]側=== |
def tag_autocomplete(request): | def tag_autocomplete(request): | ||
ret = [] | ret = [] | ||
| 17行目: | 17行目: | ||
ret.append(tag.name) | ret.append(tag.name) | ||
| − | return | + | return Http[[R]]esponse(json.dumps(ret), mimetype='text/plain') |
2020年2月16日 (日) 04:28時点における最新版
jQuery UI のAutocompleteをDjangoで実装
jQuery側
$("#txt_tag").autocomplete({
delay: 500,
source: "tag_autocomplete"
});
Django側
def tag_autocomplete(request):
ret = []
if request.method == "GET":
term = request.GET['term']
tags = Tag.objects.filter(name__icontains=term)
for tag in tags:
ret.append(tag.name)
return HttpResponse(json.dumps(ret), mimetype='text/plain')
© 2006 矢木浩人