Debugging a Django Application with PyCharm Community

PyCharm is a Jetbrains product specializing in the event of Python initiatives. It additionally comes with sturdy assist for debugging within the purposes you might be writing and Django.

Even when the skilled model undoubtedly has higher assist for Django, you should use the Neighborhood model and configure it for debugging.

Let’s examine the best way to do it.



Making a Debug configuration

Open your Django utility utilizing PyCharm and ensure to configure a digital setting. You may be taught extra about it here.

To create a debug script, click on on Run within the navigation bar and select “Edit Configuration”. You will have an analogous display screen.

We have now no configuration for this undertaking. Let’s create a configuration to run a Django utility.



Including a Django configuration

The subsequent step is to click on on “Add new run configuration” and select “Python” for the choice. You will be offered with one other widget the place it’s a must to add some primary configuration so PyCharm can know the best way to run your utility.

Screenshot from 2022-05-12 16-08-05.png

The configuration is finished, and we’re practically completed. The Pycharm model comes with useful choices, and be happy to change it to your wants.

As soon as you might be completed, click on on Apply, and congrats! You’ve your first run configuration in Django.



Working a Django utility in Debug mode

Pycharm presents two methods to run the Django utility. In Run mode or Debug mode.

The Debug mode helps you place a breakpoint in your utility’s code and analyze the state of your utility.
You get entry to the frames and variables plus their values. Fairly cool, unh? Let’s strive it.

Press Shift + F9 to run the configuration in Debug mode. You too can instantly click on on the Bug signal on the highest bar.

Screenshot from 2022-05-12 16-08-41.png

Add some breakpoints within the code of the Django undertaking. In my case, I’ve added a breakpoint in a viewset of my Django initiatives.
Then, I requested the endpoint that this viewset handles. You will have one thing comparable with completely different states and frames.

Screenshot from 2022-05-12 16-39-30.png

Your Django utility has stopped, and you’ll analyze the applying’s state. To renew, press F9.

Article posted utilizing bloggu.io. Strive it free of charge.

Add a Comment

Your email address will not be published. Required fields are marked *