[Answered ]-Alternative of Requests in django

2👍

Just call that view function and pass the request object as parameter to it.

@login_required
def show_info(request):
    r = my_api_view(request)
    return HttpResponse(r.json())

Or a better option would be to simply separate the logic into a separate function, as mentioned by @koniiiik in the comments.

EDIT: Or if you really want to hit the URL endpoint, you can simply pass on the cookie values to the request you make.

@login_required
def show_info(request):
    url = get_base_url  + "/api/get-info/"  # http://localhost:8000/api/get-info/
    r = requests.get(url, cookies=request.COOKIES)
    return HttpResponse(r.json())

Leave a comment