introduction Recently, I'm Marun (provisional), an engineer who started Django for self-development for 3 days. We are looking for a handle name ('ω') [Get started with Python Django development](https://www.amazon.co.jp/%E5%8B%95%E3%81%8B%E3%81%97%E3%81%A6%E5% AD% A6% E3% 81% B6-Python-Django% E9% 96% 8B% E7% 99% BA% E5% 85% A5% E9% 96% 80-NEXT-ONE / dp / 4798162507 / ref = tmm_pap_swatch_0? I bought _encoding = UTF8 & qid = & sr =) and started. In the book, I was developing with Pycharm and starting the server, and as a person who is developing mainly with VScode recently, I felt like hmm. I think it's good to fix the code, but I wonder if VScode can somehow start the server. So I implemented it using the debugging features I learned at VScode Meetup on December 18th! Since the introduction has become long, I will write it immediately.
Since I was developing using venv, I created a new settings.json and reconfigured venv's Python.exe as follows.
/Users/marun/test/.vscode/settings.json
{
"files.eol": "\n",
"terminal.integrated.env.windows": {
"PATH": "${workspaceFolder}/venv/Scripts;${env:PATH}"
},
// ${workspaceFolder}:C:Users/marun/It is a test.
"python.pythonPath": "${workspaceFolder}/venv/Scripts/python.exe"
}
I needed an environment variable to start Django's server on Windows, but it seems that launch.json can read the .env file, so I'll create it.
/Users/marun/test/.vscode/.env
PYTHONUNBUFFERED=1
DB_USER="[User name]"
DB_PASSWORD="[password]"
This is your own setting, so rewrite the contents as necessary. Doesn't it need environment variables for mac?
Finally, we will create launch.json, which is the basis for configuring the debug function.
/Users/marun/test/.vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"console": "integratedTerminal",
"args": [
"runserver",
"--noreload"
],
"envFile": "${workspaceFolder}/.vscode/.env",
"django": true
}
]
}
By defining envFile, I was able to read the environment variables safely. If you create this, you'll see a button like the one below in debug mode.
Press the button and the terminal will start moving. If there is no error and the output is as follows, it is successful! Let's actually hit the URL surrounded by red to check it!
It's the second time I've written an article on Qiita, and I'm still lacking in study, so I can't say that I'm an engineer, but I'll continue to implement and output what I wish I had. I think. May my fellow countrymen with similar worries be saved in this article. Also, I am waiting for comments such as that it is better to do this or that this is wrong! Give me your knowledge! !!
[Get started with Python Django development](https://www.amazon.co.jp/%E5%8B%95%E3%81%8B%E3%81%97%E3%81%A6%E5% AD% A6% E3% 81% B6-Python-Django% E9% 96% 8B% E7% 99% BA% E5% 85% A5% E9% 96% 80-NEXT-ONE / dp / 4798162507 / ref = tmm_pap_swatch_0? _encoding = UTF8 & qid = & sr =), but I think it's a very good book because it's full color and you can learn various techniques other than Django (arguments are welcome).
How do people look for a handle name or a nice icon? .. ..
Recommended Posts