четверг, 7 июня 2018 г.
Debug django code without server restart
It is nice to debug new function or whole django API without need to rebuild or restart server. Just copy/paste your code to django shell and test it there.
вторник, 5 июня 2018 г.
пятница, 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 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
- 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
Подписаться на:
Сообщения (Atom)