As the title says. I've built a learning environment for studying Django, so I'll leave a note of the steps here. There is no explanation at all, so I'm not interested in what kind of tools are included or how it works, or I already know it, so let me just build the environment! It is an article for people who say. Or rather, it's my memorandum. I am running in a Windows 10 environment.
――I want to study Django --I want to do step execution using a debugger with VS Code --I don't want the Python virtual environment to be annoying, I don't want to pollute the PC environment
⇒ You should create an environment with Docker!
If WSL2 (Windows Subsystem for Linux 2) has not been set up, set up WSL2 first. The procedure is as follows. https://docs.microsoft.com/ja-jp/windows/wsl/install-win10
You can use any Linux distribution. I chose Ubuntu.
Install Docker Desktop. https://www.docker.com/products/docker-desktop There is no problem if you install with the default according to the installer.
Download and install VS Code. https://azure.microsoft.com/ja-jp/products/visual-studio-code/
Next, install the extension called Remote Containers. https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers
Originally, I would write a Dockerfile from here, create a VS Code configuration file, and go crazy, but since I created a set of environment files for learning, please get it from the following. https://github.com/nendo-code/djangostudyenv
In VSCode, open the "django studyenv" folder you got earlier
Press the green icon at the bottom left of the VS Code screen. When the command palette is displayed, select "Remote-Containers: Open Folder in Container". A dialog for selecting a folder will appear, so specify the folder for the "django studyenv" you obtained earlier.
Environment construction (and installation of VS Code extension) by Docker will start. Click "Starting Dev Container (show log)" to display the progress of environment construction.
Now that you have a Django development environment built on your Docker container, let's create a Django project. Open a terminal and execute the following command.
$ cd /code/web
$ django-admin startproject app
This will create a django project called "app". Select Python: Django from the Run menu on the left side of VS Code and press the Start Debugging button.
This will start the application created with django, so try it http://localhost:8000/ To access. If the start page of django is displayed as shown below, it is successful.
This completes the environment construction. You can then put breakpoints in your code to stop them, step through them, or develop with a debugger.
If you want to customize the environment, you can customize it by modifying the following parts.
・ I want to put VS Code extension on the container side ⇒ Add the extension you want to include in "extensions" of .devcontainer/devcontainer.json.
-I want to change the name of the django project folder, I want to change the runtime options ⇒ Edit the configurations in .vscode/launch.json.
https://docs.docker.jp/compose/django.html https://docs.djangoproject.com/ja/3.1/intro/tutorial01/ https://qiita.com/nokonoko_1203/items/33a05c86f359027afb33 https://qiita.com/firedfly/items/00c34018581c6cec9b84
Recommended Posts