Visual Studio Code is the best *free* text editor for writing code available today. It has the benefit of being lightweight, and therefore very performant, while still offering many of the features that you would normally expect in a more robust Integrated Development Environment. Visual Studio Code is also great to use when working with Python and Django since it has extensions that make it easy to code in Python and Django. Let’s get Visual Studio Code set up for working with our new Django Project now.
Install Visual Studio Code
Visual Studio Code is available for macOS, Windows x64, and Linux x64 machines as a simple installable file. Simply visit https://code.visualstudio.com/ and select the installation option that is right for you. Visual Studio Code can be used with Python, HTML, CSS, JavaScript, C++, Java, and much more. This robust ability to edit any type of programming language is possible because of the Extensions ecosystem built into Visual Studio Code. It is easy to find an extension to support almost any type of project you like.
Configuring Extensions
There are a number of extensions for Visual Studio Code that will help with Python and Django development. We can add those to our VS Code installation now.
Python Extension By Microsoft
The first extension to install to make working with Python and Django easier is the Python extension for Visual Studio Code extension. In Visual Studio Code, first, click on the Extensions icon.
The Extensions Marketplace will expand open, and there you can type in “Python” into the search box. A large list of extensions will be displayed for you. The one you want to install has the text, “IntelliSense (Pylance), Linting, Debugging (multi-threaded, remote), Jupyter Notebooks, code formatting, refactoring, unit tests, and more.” with almost 40 million downloads. This is the official Python extension provided by Microsoft. In our case, it has already been installed, but if you need to, do click “Install” to get it installed on your system.
Python-autopep8
The Python autopep8 extension is also a nice one to have to ensure that the current best practices for Python code formatting are applied to any Python file you work on.
Django Extensions
As long as you have the main Python extension installed, you will be able to work in Django Projects just fine. If you are curious, however, there are many additional Extensions that focus directly on the Django framework and some of them may be of interest to you. Installing any of these is optional.
Some of the more popular Django Extensions for Visual Studio Code are listed here.
- Django extension for Visual Studio Code
- Django Templates for Visual Studio Code
- Django Snippets
- Django support for Visual Studio Code
- django-intellisense
Open A Django Project In VS Code
Now that the needed extensions are installed, we can open the new Django project that we recently created. To do this select File, then Open Folder, and select the outermost directory of the Django Project. When a Django project is created, there will be two folders with the same name, open the outer folder in the IDE.
The resulting file structure in Visual Studio Code should be the familiar files we are used to with any Django project. These are asgi.py, settings.py, urls.py, wsgi.py, and manage.py.
Python VS Code Integration
To ensure that Visual Studio Code is synced up with the Python installation on our machine, we’ll want to enable the Status Bar and confirm that it shows the Python installation listed as active and working.
You should then see something like the following at the bottom of the IDE, which indicates everything is ready to go.
How To Use Visual Studio Code With Django Summary
Great work! Your Visual Studio Code installation is ready for working with Python and Django. Learn More About How To Use Visual Studio Code With Django:
- Python Tutorial Django (code.visualstudio.com)
- Visual Studio Code Setup For Django Developers (djangocentral.com)
- Microsoft Python Sample Vscode Django Tutorial (github.com)
- Visual Studio Code Setup For Python Django Development (vinodpandey.com)
- Django Projects In Visual Studio Code (automationpanda.com)
- Visual Studio Code With Python Django (taswar.zeytinsoft.com)
- How To Run Django In Vs Code (ozanecare.com)
- Django Debugging Vs Code (testdriven.io)