How to GET request if login_required in DJango

Viewed 576

Here my API:

@login_required
@api_view(['GET'])
def get_order(request):

    order_list = Order.objects.values("user_name",
                        "user_surname",
                        "order_date").all()

    return HttpResponse(json.dumps([x for x in order_list])

The problem is when i add @login_required, i'm trying to do a Postman GET request using BASIC authentication with username and password. If i remove the @login_required, i can perform a succesful GET request without auth in Postman.

1 Answers

First, login with your browser. Next, locate where the corresponding authentication cookie is stored in your browser. Copy it to your clipboard. Finally, paste the cookie and pass it along with the GET request in Postman:

enter image description here

The name of the cookie is sessionid.

Related