Skip to content

Instantly share code, notes, and snippets.

@mentix02
Last active February 11, 2021 07:09
Show Gist options
  • Save mentix02/eb6014fc0404a29bb6dd5b7252ea6f94 to your computer and use it in GitHub Desktop.
Save mentix02/eb6014fc0404a29bb6dd5b7252ea6f94 to your computer and use it in GitHub Desktop.
from django.views import View
from django.http import JsonResponse
from django.views.generic import TemplateView
from book.search import search
class IndexView(TemplateView):
template_name = 'index.html'
class SearchBookTitleAPIView(View):
@staticmethod
def get(request):
q: str = request.GET.get('q')
if not q:
return JsonResponse({'error': 'Query not provided.'}, status=400)
else:
return JsonResponse(search(q), safe=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment