2

A list is created. I want to display the list in the template.

search_query=[]
#...
#code here
#...

return render(request, 'query/list.html', {'search_query'})

But it is giving this error - "context must be a dict rather than set."

In the list.html

{% for c in suggest_search_query%}
    <p>{{c}}</p>
{% endfor %}

1 Answer 1

1

The error is in the call to render(..):

return render(request, 'query/list.html', {'search_query'})
#                                         ^     set      ^

You here did not construct a dictionary, but a set (the notation is a bit similar). A set is a collection of unique hashable values. But you do not map keys to values in a set, that is what a dictionary does.

You need to convert it to:

return render(request, 'query/list.html', {'suggest_search_query': search_query})

to define a dictionary that maps suggest_search_query to the search_query variable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.