As for django to collect the following structure for the transmission on the front?

To the front you need to give this JSON
{
"results": [
{
"title": "Result Title",
"url": "/optional/url/on/click",
"description": "Optional Description"
},
{
"title": "Result Title",
"description": "Result Description"
}
],
// optional action below results
"action": {
url: '/path/to/results',
"text": "View all 202 results"
}
}

I have a function following:
def search_result(request):
 if not request.user.is_authenticated():
 return redirect('login')

 search_str = request.GET['q']
 search_str = search_str.replace('.', '')
 search_str_split = search_str.split(' ')
 search_result_data = []
 for item in search_str_split:
 search_result_data = Task.objects.filter(Q(title__contains=item) |
 Q(description__contains=item)) \
 .filter(Q(author=request.user) | Q(performer=request.user)) \
.order_by(
'-date_finish')
 result = dict()
 result['result'] = []
 for res in search_result_data:
 result['result'].append({'title': res.title, 'url': 'task_det', 'description': res.description})

 result['action'] = {url: '/path/to/results',
 "text": "View all 202 results"}

 return JsonResponse(result)


Json content is the same
b'{"result": [{"title": "\\u043f\\u0440\\u0438\\u043a\\u0440\\u0443\\u0442\\u0438\\u0442\\u044c REST API", "url": "task_det", "description": ""}, {"title": "\\u043f\\u0440\\u0438\\u043a\\u0440\\u0443\\u0442\\u0438\\u0442\\u044c REST API", "url": "task_det", "description": ""}], "action": {"url": "/path/to/results", "text": "View all 202 results"}}'
June 10th 19 at 15:00
0 answer

Find more questions by tags JSONDjango