Debugging a Django Application with PyCharm Community

PyCharm is a Jetbrains product focusing on the development of Python projects. It also comes with robust support for debugging in the applications you are writing and Django.

Even if the professional version definitely has better support for Django, …


This content originally appeared on DEV Community and was authored by Mangabo Kolawole

PyCharm is a Jetbrains product focusing on the development of Python projects. It also comes with robust support for debugging in the applications you are writing and Django.

Even if the professional version definitely has better support for Django, you can use the Community version and configure it for debugging.

Let's see how to do it.

Creating a Debug configuration

Open your Django application using PyCharm and make sure to configure a virtual environment. You can learn more about it here.

To create a debug script, click on Run in the navigation bar and choose "Edit Configuration". You'll have a similar screen.

Screenshot from 2022-05-12 16-07-13.png

We have no configuration for this project. Let's create a configuration to run a Django application.

Adding a Django configuration

The next step is to click on "Add new run configuration" and choose "Python" for the option. You'll be presented with another widget where you have to add some basic configuration so PyCharm can know how to run your application.

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

The configuration is done, and we are nearly done. The Pycharm version comes with handy options, and feel free to modify it to your needs.

Once you are done, click on Apply, and congrats! You have your first run configuration in Django.

Running a Django application in Debug mode

Pycharm offers two ways to run the Django application. In Run mode or Debug mode.

The Debug mode helps you place a breakpoint on your application's code and analyze the state of your application.
You get access to the frames and variables plus their values. Pretty cool, unh? Let's try it.

Press Shift + F9 to run the configuration in Debug mode. You can also directly click on the Bug sign on the top bar.

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

Add some breakpoints in the code of the Django project. In my case, I've added a breakpoint in a viewset of my Django projects.
Then, I requested the endpoint that this viewset handles. You'll have something similar with different states and frames.

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

Your Django application has stopped, and you can analyze the application's state. To resume, press F9.

Article posted using bloggu.io. Try it for free.


This content originally appeared on DEV Community and was authored by Mangabo Kolawole


Print Share Comment Cite Upload Translate Updates
APA

Mangabo Kolawole | Sciencx (2022-05-13T05:14:02+00:00) Debugging a Django Application with PyCharm Community. Retrieved from https://www.scien.cx/2022/05/13/debugging-a-django-application-with-pycharm-community/

MLA
" » Debugging a Django Application with PyCharm Community." Mangabo Kolawole | Sciencx - Friday May 13, 2022, https://www.scien.cx/2022/05/13/debugging-a-django-application-with-pycharm-community/
HARVARD
Mangabo Kolawole | Sciencx Friday May 13, 2022 » Debugging a Django Application with PyCharm Community., viewed ,<https://www.scien.cx/2022/05/13/debugging-a-django-application-with-pycharm-community/>
VANCOUVER
Mangabo Kolawole | Sciencx - » Debugging a Django Application with PyCharm Community. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/05/13/debugging-a-django-application-with-pycharm-community/
CHICAGO
" » Debugging a Django Application with PyCharm Community." Mangabo Kolawole | Sciencx - Accessed . https://www.scien.cx/2022/05/13/debugging-a-django-application-with-pycharm-community/
IEEE
" » Debugging a Django Application with PyCharm Community." Mangabo Kolawole | Sciencx [Online]. Available: https://www.scien.cx/2022/05/13/debugging-a-django-application-with-pycharm-community/. [Accessed: ]
rf:citation
» Debugging a Django Application with PyCharm Community | Mangabo Kolawole | Sciencx | https://www.scien.cx/2022/05/13/debugging-a-django-application-with-pycharm-community/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.