Answers for "leduong django api"

1

leduong django api

from time import time

from django.http import JsonResponse


def api_params(request):
    ts = time()
    if request.method == "GET":
        try:
            params = request.GET.dict()
            results = JsonResponse({"params": list(params)})

        except Exception as e:
            results = JsonResponse({"errors": list(e)})
    print('Took: ', time() - ts, 's')
    return results
Posted by: Guest on June-14-2021

Python Answers by Framework

Browse Popular Code Answers by Language