- Create Virtual Enviorment
# Linux
sudo apt-get install python3-venv # If needed
python3 -m venv .venv
source .venv/bin/activate
# macOS
python3 -m venv .venv
source .venv/bin/activate
# Windows
py -3 -m venv .venv
.venv\scripts\activate
- Launch PyCharm.
- Click on File > Open....
- Navigate to your existing Django project folder and click OK.
PyCharm will load the Django project and index the files, which may take a few minutes for large projects.
- Go to File > Settings > Project: your_project_name > Python Interpreter.
- Click on the gear icon and choose Add....
- In the left pane, select Existing environment.
- Click on the ... button to browse to your Python interpreter. It's usually located in the venv/bin/ folder inside your project folder.
- Click OK to close the dialogs.
This sets the Python interpreter for your Django project.
- Go to File > Settings > Languages & Frameworks > Django.
- Check the Enable Django Support box.
- In the Django project root field, enter the directory which contains manage.py.
- In the Settings field, enter the location of your settings.py file, usually your_project_name/settings.py.
- Click OK to close the dialog.
This allows the IDE to find django setup files
After giving it a minut you will be able to run the debugger You should be able to use the debugger which is on the upper right corner
- Open the project folder in VS Code by running code ., or by running VS Code and using the File > Open Folder command.
- In VS Code, open the Command Palette (View > Command Palette or (⇧⌘P)). Then select the Python: Select Interpreter command:
- The command presents a list of available interpreters that VS Code can locate automatically (your list will vary; if you don't see the desired interpreter, see Configuring Python environments). From the list, select the virtual environment in your project folder select the enviorment
- Switch to Run view in VS Code (using the left-side activity bar or F5). You may see the message "To customize Run and Debug create a launch.json file". This means that you don't yet have a launch.json file containing debug configurations. VS Code can create that for you if you click on the create a launch.json file link
- Select the link and VS Code will prompt for a debug configuration. Select Django from the dropdown and VS Code will populate a new launch.json file with a Django run configuration. The launch.json file contains a number of debugging configurations, each of which is a separate JSON object within the configuration array.
- Choose the Django configuration
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
],
"django": true
},
- Test the configuration by selecting the Run > Start Debugging menu command, or selecting the green Start Debugging arrow next to the list (F5):