пятница, 1 июня 2018 г.

Debug django rest API from shell

It is possible to debug step by step Django rest framework API in pdb/ipdb debugger.
  • Import API on line (1)
  • Replace root@root with valid email of user with correct permissions on line (2)
  • Paste code in shell and run
  • Execution will start on Django internal code. To go to your API use breakpoints.

import ipdb #or pdb
_user = User.objects.get(

email__contains='root@root')#(2)valid user email
from rest_framework.test import APIRequestFactory
from rest_framework.test import force_authenticate
_factory = APIRequestFactory()

_request=_factory.post('', {})
force_authenticate(_request, _user)
from project.apps.users.api import ApiMySettingsView as api # (1)
_view=api.as_view()

responce=ipdb.runcall(_view,_request) #debug
#responce=_view() #just run
vars(responce)


http://www.django-rest-framework.org/api-guide/testing/
https://docs.python.org/3/library/pdb.html

Комментариев нет:

Отправить комментарий