Skip to content

Instantly share code, notes, and snippets.

@gpichot
Created September 21, 2018 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpichot/77aa6bb305291035554e0aba005ef4f5 to your computer and use it in GitHub Desktop.
Save gpichot/77aa6bb305291035554e0aba005ef4f5 to your computer and use it in GitHub Desktop.
Request Django Rest Framework view response from shell with authentication
u = User.objects.get(username=username)
from rest_framework.test import APIRequestFactory, force_authenticate
factory = APIRequestFactory()
request = factory.get(url, format='json')
force_authenticate(request, u)
view = MyView.as_view()
response = view(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment