59π
For VSCode (full disclosure, Iβm one of the VSCode developers) try installing the Python extension to get started.
This documentation covers debugging Django. There should be a included debug configuration or you can add your own to the launch.json
file:
{
"name": "Django",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config.python.pythonPath}",
"program": "${workspaceRoot}/manage.py",
"args": [
"runserver",
"--no-color",
"--noreload"
],
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput",
"DjangoDebugging"
]
}
The Python extension also provide many other features that you may find useful.
6π
VSCode has an official tutorial explaining this:
https://code.visualstudio.com/docs/python/tutorial-django
There are several steps that need to be taken, which I donβt all want to write out manually, since there are quite some steps, but Iβll try to summarize what needs to be done:
The text below is basically a partial copy of the above tutorial, I am not claiming I came up with this myself.
1. Make sure to check out the prerequisites (use VS Code Python extension, install Python on local machine) link to docs
2. Use Python virtual environment link to docs
Besides using a Python virtual environment, you also need to select the Python executable inside this virtual environment as the interpreter in VS Code. This can be done like so:
In VS Code, open the Command Palette (View > Command Palette or (Ctrl+Shift+P)). Then select the Python: Select Interpreter
Then you select the Python executable inside your virtual environment, which you can recognize by itβs path.
3. Create debugger lauch profile
as described here, in the documentation
upper left of the VS Code window)
4. Now you can start debugging
this part of the documentation will give you an introduction on how to do that
- [Django]-Django QueryDict only returns the last value of a list
- [Django]-Django REST framework: type object X has no attribute 'get_extra_actions'
- [Django]-Stack trace from manage.py runserver not appearing
3π
Only experimental configuration works for me.
{
"name": "Django",
"type": "pythonExperimental",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"django": true
},
Standard config causes Unverified breakpoint
issue.
- [Django]-Django Background Task
- [Django]-How to disable Django's CSRF validation?
- [Django]-How to put timedelta in django model?
2π
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\\manage.py",
"args": [
"runserver"
],
"django": true
},
{
"name": "Django: makemigrations",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\\manage.py",
"args": [
"makemigrations"
],
"django": true
},
{
"name": "Django: migrate",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\\manage.py",
"args": [
"migrate"
],
"django": true
},
]
}
- [Django]-How to add superuser in Django from fixture
- [Django]-Django accessing ManyToMany fields from post_save signal
- [Django]-How to save a model without sending a signal?
1π
Nothing worked for me until I had disabled auto reload (--noreload
as an argument is crucial, not really sure why it causes problem with debugging)
- [Django]-Class views in Django
- [Django]-Django view β load template from calling app's dir first
- [Django]-Django return HttpResponseRedirect to an url with a parameter