1

I'm implementing some search mechanism on my app, trying to get the query from input, look for it in database(sqlite) and render it to template. Problem is that I'm getting error:

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

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.

1 Answer 1

1

You are not returning the return value of search_query, you should return it:

def api_search(request): if request.method == "GET": query = request.GET.get('q') search = 'some API with {query} inside it' return search_query(request,search,query) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.