-
Notifications
You must be signed in to change notification settings - Fork 5
Debug Django with VS Code
This document will explain how to set up a Python (specifically Django) debugging environment inside VS Code. These instructions should work on any system: Windows, Mac, or Linux. Prerequisites
- Python 3.x – Most of our Django projects utilize 3.8.
- Pip
- Virtual Environment packages from Pip:
- virtualenvwrapper (for Linux and Mac)
- virtualenvwrapper-win (for Windows)
- virtualenvwrapper (for Linux and Mac)
https://code.visualstudio.com/docs/setup/linux
- Install the package key and repository:
- [ sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc ]
- [ sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo' ]
- Update package cache and install package with dnf:
- [ sudo dnf check-update ]
- [ sudo dnf install code ]
- Create a virtual environment for the project if one doesn’t already exist.
- To select a specific environment, use the Python: Select Interpreter command from Command Palette (⇧⌘P).
- Python: Select Interpreter Virtual Env
- Install dependencies from the requirements.txt file for the project.
- $ pip3 install -r requirements.txt
- $ pip3 list -o lists any outdated packages
- $ sudo pip3 install [package_name] --upgrade updates package
- $ source ~/.bashrc If issue finding virtualenv run the command
- Navigate to the folder level containing manage.py file.
- Open this folder level with VS Code.
- Create a new launch.json file for debugging:
- Select Debug > Open configurations
- Select the Django option
- Add the python virtual environment path to the launch.json file. Insert a new setting for pythonPath below the line for “program”: [ "pythonPath": "/home/dyoung11/.virtualenvs/datasearch/bin/python" ]
- Press F5 to begin debugging.
- Open a browser and navigate to localhost:8000 (the port may vary).
NOTE: At this time the debugger doesn’t automatically open a browser. This functionality is likely possible, will need to research it some more.
FoodWaste is developed and maintained by Office of Research & Development (ORD), Center for Environmental Solutions & Emergency Response (CESER), Land Remediation & Technology Division (LRTD), Environmental Decision Analytics Branch (EDAB), U.S. Environmental Protection Agency, Cincinnati, OH 45268, under Mozilla Public License Version 2.0. See OMB Memorandum M-16-21 Section 4 & Releasing Open Source Code.