views didn't return an HttpResponse object. It returned None instead

Refresh

April 2019

Views

7 time

0

I'm implementing some search mechanisam on my app, trying to get query from input, look for it in database(sqllite) and render it to template. Problem is that I'm getting ".views didn't return an HttpResponse object. It returned None instead" error.

Logic is like: 1) making a function which will check given query

def search_query(request,search,query):

checking = check_in(query) #check if query is in DB

if checking == False: #if not, get data from search api and save it
    search_querys = requests.get(search)
    json_search = search_querys.json()   
    for each in json_search['data']:    
        user_id = each['id']
        name = each['name']
        picture = each['picture']['data']['url']
        Profiles.objects.create(user_id=user_id, name=name, picture=picture)

    return render(request, 'FB_search/home.html') 

else:   # <--assuming that here's the problem. For testing purpose, I'm writing query for which I know that they are in DB and I'd like to return in tamplet
    context = {
        'profiles': Profiles.objects.filter(Q(user_id__startswith=query) | Q(name__startswith=query))
    }       

    return render(request, 'FB_search/home.html', context)

2) calling function above in my endpoint like:

def api_search(request):
    if request.method == "GET":
       query = request.GET.get('q')
       search = 'some API with {query} inside it' 
       search_query(request,search,query)

When I try to call the "search query" funtion I'm getting mentioned error. Any suggestion?

Thank you.

0 answers