2020/03/13 Slightly modified to match VSCode Version 1.43.0
Beginners longed for the word debug, and learned that VS Code can actually do it, so I set it up. The memorandum. I think the advantage is that once you set it up, you can just press the Debug button to enter the virtual environment and run the server. You can save yourself the trouble of typing source myenv / bin / activate
or python manage.py run server
back and forth between your browser, Terminal and VS Code. A little easier.
Django Tutorial in Visual Studio Code
Ubuntu 18.04 LTS Python 3.6.9 Django 2.2.8 or 3.0
$ mkdir myproject
$ cd myproject
$ python3 -m venv myenv
#It seems that there are various virtual environments, but here you can choose venv.
$ source myenv/bin/activate
#I put it in a virtual environment.The prompt in the virtual environment is as follows(myenv)$To.
(myenv)$ pip install django
#Django is installed(Django to specify version==2.2.Enter as 8)
(myenv)$ django-admin startproject config .
#Finally the project started.The name is config.The reason is from the "Django textbooks that can be used in the field" book.
#Last".Don't forget.If you don't add it, you will have more directories, which is a little troublesome..
(myenv)$ deactivate
#Exit the virtual environment once
The current directory structure is as follows
.
├── config
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── manage.py
└── myenv
Start VSCode and click Open Folder ... from File to open the myproject directory.
Install Python Extention
Select Command Palette ... in View and click Python: select interpreter
Select the interpreter for the virtual environment (myvenv in this case)
Click the bug icon on the far left, then click the gear icon and select Python
Create a launch.json file
→ select Python from the display
Select Django from the view
DEBUG Press the green triangle button on the right to automatically run server
Fly to 127.0.0.1:8000 with a web browser and launch the usual rocket
This saves you the trouble of launching multiple Terminals, selling commands each time, and going back and forth between windows. Convenient. I realized that VS Code is not just an editor, but a development environment, which is amazing.
The problem is ... ** beginners don't know what to do with debugging **.
Recommended Posts