6đź‘Ť
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.
45đź‘Ť
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.
- [Django]-How do I POST with jQuery/Ajax in Django?
- [Django]-Annotating a Sum results in None rather than zero
- [Django]-In Django is there a way to display choices as checkboxes?
38đź‘Ť
-
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
- [Django]-Django: add image in an ImageField from image url
- [Django]-About IP 0.0.0.0 in Django
- [Django]-Testing email sending in Django
3đź‘Ť
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
- [Django]-Get count of related model efficiently in Django
- [Django]-Django: Open uploaded file while still in memory; In the Form Clean method?
- [Django]-Difference between auto_now and auto_now_add
0đź‘Ť
It depends on how you want to run your code for debugging.
Scenario 1
You might not have a frontend or views. You just want to directly trigger the functions you want to test.
In this case, you want to start the debugger by running python manage.py shell
. Then, you will be able to run commands directly against your code and trigger any breakpoints. A simple example:
from structure.models import Clients
Clients.objects.create()
Scenario 2
You have a frontend or will be calling your views through an API tester (Postman, etc.) to trigger the functionality you want to test.
Then you want to start the debugger by running python manage.py runserver
. Now, as long as the right requests are getting sent, any breakpoints you have set will get triggered.
- [Django]-Equivalent of PHP "echo something; exit();" with Python/Django?
- [Django]-Function decorators with parameters on a class based view in Django
- [Django]-How can I upgrade specific packages using pip and a requirements file?