Under the hood: development in debugger mode

Let’s make a small break in this series of articles regarding backend development for web3 projects with one I hope useful small detail. Namely: development in debugger mode.

People often jump to debugger at the point when they are already highly frustrated with some stubborn bug. When they already hit the wall and there is no easy solutions. Then they start to think about atomic solution! Run program in debugger mode. And of course there is nothing wrong about that. But for peace of your mind I will propose one simple and slightly different approach: develop your program all the time in debugger mode (not only when problems emerge). This will allow you to see deeper layers of your program. In return this will speed up development time and improve clarity and situation awareness about what is going under the hood at any give point in program execution.

VS Code allow us to develop Django app in debugger mode very easily.

Step one: open your VS code in your Django project root folder

Step two: press debugger button from left side

Press create a launch.json and select Python and then Django and you will get in your root folder: 1. new (local Django project related) launch.json where all general settings are located; 2. newly created hidden VS code folder .vscode (launch.json is there).

Now just open view.py (we presuppose here that you already have settings.py and urls.py setted) from your Django app and make breakpoint (in case you miss breakpoint are positions where code will stop and allow you to inspect what is going on).

Last: let’s run Django server from debugger like this

Now if you go to your browser and type in address bar http://127.0.0.1:8000/name_of_your_app_path/ and go back to VS Code. You will see that debugger stop execution of your code at breakpoint.

Then in left panel you can inspect what is going on with your objects and have in depth view in inner workings of your program. I think this can be extremally helpful at any give point in developmental process.

原文链接:Under the hood: development in debugger mode

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享
Change your thoughts and you change your world.
改变你的思想,你就能改变自己的命运
评论 抢沙发

请登录后发表评论

    暂无评论内容