четверг, 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 г.

To my surprise, pep8 style guide check tool was renamed to pycodestyle in 2016. The package is deprecated now.
Thought autopep8 not.

pep8 has been renamed to pycodestyle (GitHub issue #466)
Use of the pep8 tool will be removed in a future release.
Please install and use `pycodestyle` instead.

пятница, 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