[PYTHON] Until you run server Django in Visual Studio Code

prologue

Load Django into Visual Studio Code and start your web server. If you don't have an editor, you'll have to run "python manage.py runserver" manually, With VSC, you can start the development WEb server with the touch of a button, which is convenient. It took a long time to set it, so make a note of it.

procedure

Click "Add Folder" from the Explorer screen at the top left. 1.png

Select a project folder. This is the project folder where you created Django with "django-admin startproject project name". 2.png

The workspace is now set up. Next, set up so that the development web server can be started. Next, open the debug screen with the bug icon on the left and press "Create launch json file". The folder name of the workspace is displayed above, so select it.

Then select the target environment. But unfortunately there is no "django" in the candidates. 4.png

You need to open the django file once. Open views.py and try again. Django is displayed as a candidate, so select it. 5.png 6.png

A launch.json has been created for Django. 7.png

Now that the settings are in place, let's start the development web server. Press the triangle mark on the upper left. If the bottom turns orange, you have started. 8.png

I will check it for the time being. The screen is displayed, so confirmation is OK. 9.png

Anti-pattern

① No such file or directory hogehoge manage.py As you can see in the error message, manage.py is missing. The workspace location is specified incorrectly. I used to specify the app folder as the workspace instead of the project folder.

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\work\\hogehoge\\manage.py'

② SyntaxError: invalid syntax The error and message look like this

  File "C:\Users\hoge\anaconda3\lib\runpy.py", line 236, in _get_code_from_file
    code = compile(f.read(), fname, 'exec')
  File "c:\work\02_Implementation\hogehoge\.vscode\launch.json", line 2
    //You can use IntelliSense to learn the available attributes.
     ^
SyntaxError: invalid syntax

The cause was that I chose python over Django when creating launch.json. Apparently you're trying to run launch.json in python? Seems to be the direct cause. Although it is in English, it is also described in stack overflow. There is.

If you specify Django as you did in the procedure and recreate launch.json, you can start it normally.

epilogue

I was wondering if I could do it more quickly, but it took longer than I expected. If you go straight, it will take about 5 minutes.

Recommended Posts

Until you run server Django in Visual Studio Code
Run Python in C ++ on Visual Studio 2017
Time when terminal disappears in Visual Studio Code
Until you run the changefinder sample in python
Until you create a new app in Django
Settings for Python coding in Visual Studio Code
Install numpy in Visual Studio 2019
Bottle Pug in Visual studio 2019
Python development in Visual Studio 2017
Python development in Visual Studio
How to use linux commands in Visual Studio Code terminal
Do something like a Python interpreter in Visual Studio Code
Java with Visual Studio Code (Part 2)
Until you put Python in Docker
Until you start crawling in Scrapy
Bash, Python, Javascript, code command, etc. in Visual Studio Code on Mac
run uwsgi server in uwsgi-gevent mode
Remote debugging in Visual Studio (Linux)
Until you run python with apache
How to run TensorFlow 1.0 code in 2.0
Until you put pyaudio in Mavericks
Until you install and run matplotlib
[Introduction to machine learning] Until you run the sample code with chainer
Until you can step in PyCharm + Django + virtual environment (pyvenv + Python3) (mac)
Installation of Visual studio code and installation of python
When you can't call base.html in Django
Create a Python development environment in 10 minutes (Mac OS X + Visual Studio Code)
Highlight Python user function calls in Visual Studio Code (vscode) Default Dark + theme
Until you install Python with pythonbrew and run Flask on a WSGI server
Tips when amateurs use Flask in Visual Studio
Until you CI what you made with Django with Jenkins
Until you install Caffe and run the sample
Run the task in the background on the sshed server
Build Python development environment with Visual Studio Code
How to set Django DB to mongodb visual studio 2019
How to run some script regularly in Django
Django with Python Tools 2.2 for Visual Studio (PTVS 2.2)
Data Science Workloads and RTVS in Visual Studio 2017
Code often used in Python / Django apps [prefectures]
[Visual Studio Code] [Python] Tasks.json + problemMatcher settings for Python