how do i debug/breakpoint my django app using pycharm?
The problem is that the DJANGO_SETTINGS_MODULE
variable which should point to your project's settings file, wasn't set anywhere, since the variable is reported to be undefined.
The solution and an explanation you can refer to can be found in a previous post
So i gave all the answers here a +1 for trying - but they're not the issue. Near as i can tell, the answer is that pycharm is broken. Which is a pain, but the solution is easy -
IF you dont' want to use the little green button at the top of pycharm, or use the pycharm debugging feature? then don't worry, you don't need to do anything. Continue using ctrl-shift-r and runserver (or whatever your shortcut to manage.py is)
IF you do want to use the little green "run" button, or if you want to use pycharm's debugging kit, then you absolutely cannot use the "add_to_builtins", at least in the settings.py file (I never put it anywhere else myself, pycharm might require it elsewhere?). add_to_builtins
doesn't work in pycharm - it gets itself caught in a loop of grave consequences when you use the little green button or the debug button. Using ctrl-shift-r and runserver doesn't, curiously, have this problem.
The good news is that "add_to_builtins" isn't a must-have, just a nice-to-have. Just add the "{% load x %}" command to each template where you use x and you will be set. Alternatively, save a hundred bucks and use some sort of free eclipse tool.
The problem has little to do with DJANGO_SETTINGS_MODULE. Pycharm sets this when creating the project. Instead Go to the little green "Play button" for running scripts. You want to configure it to run manage.py, ie you are configuring the play button to run the command python manage.py runserver
.
Breakdown:
python
------> run with python Intepreter
manage.py
--------> run this script
runserver
---------> arguments
So go to the drop down to the left of the green play button
,
click on edit configurations. You will get a screen like this one
.
Fill it out as shown locating your manage.py source script. Make sure you include runserver on the arguments box. Now you can click the green debug button and you program will stop at the first breakpoint it ecounters allowing you to descend upon it in full debug mode watch variables and all. Now you can manually type python manage.py runserver on the terminal or use your newley configured run button.
Setup your virtual environment
- Create or open your project in PyCharm
- Go to File - Settings in the menu (or just click on the settings icon)
- Go to Python Interpreter
- Click on Add in the top
- Go to the bin folder where you created the virtual environment and select python
Set a breakpoint
- Next to the line of code you want to set the breakpoint. To the left there is usually a grey line. Usually next to the line numbers. Just click there and a big red dot will appear. Looks like this
Hit the Run in debug mode button.
Next to the Green play button there is a button with a bug on it. Use that to launch the runserver in debug mode. Now when you use your web application and the code hits the breakpoint it will stop there and you will be able to step in and over or resume in pycharm.
- If you still are not able to debug you might need to edit the pycharm project config. You can do that like this.
You can look at http://garmoncheg.blogspot.it/2012/01/establishing-dev-environment-with.html too