1
How can I troubleshoot the error that is popping up?
I believe the issue may be related to it being a dictionary. Any suggestions on how to fix this problem?
views
search(request):
if "q" in request.GET:
querystring = request.GET.get("q")
if len(querystring) == 0:
return redirect("/search/")
posts = RelatedPost.objects.filter(text__icontains=querystring).count()
users = User.objects.filter(username__icontains=querystring)
context = {"posts": posts, "users": users}
return render(request, 'registration/search.html', context)
else:
return render(request, 'conversation/search.html')
`
<div class="row mt-3">
<div class="col-4">
<h5><strong>Posts</strong></h5>
{% if posts %}
{% for post in posts %}
<p>{{ post.text }}</p>
{% endfor %}
{% else %}
<p>---</p>
{% endif %}
</div>
<div class="col-4">
<h5><strong>User</strong></h5>
{% if users %}
{% for user in users %}
<p>{{ user }}</p>
{% endfor %}
{% else %}
<p>---</p>
{% endif %}