📌 Setting up Django in VS Code (English Guide)

This comprehensive guide will help you install Python, set up a virtual environment, and configure Visual Studio Code to start building your first Django web application.

1 Step 1: Install Python
  • Visit the official website: python.org and download the latest version for Windows.
  • Run the installer. CRITICAL: Ensure you check the box that says "Add Python to PATH" at the bottom of the installer window before clicking "Install Now".
  • To verify installation, open Command Prompt and type:
python --version
2 Step 2: Install VS Code and Extensions
  • Download VS Code from code.visualstudio.com and install it.
  • Open VS Code, click the Extensions icon on the left sidebar (or press Ctrl + Shift + X).
  • Search for and install the following extensions:
    • Python (by Microsoft) - Essential for linting and formatting.
    • Django (by Baptiste Darthenay) - Provides Django syntax highlighting and snippets.
3 Step 3: Create a Virtual Environment

It is a best practice to create an isolated environment for every Python project so dependencies do not conflict.

  • Create a new folder for your project on your computer (e.g., my_django_project) and open this folder in VS Code.
  • Open the integrated terminal in VS Code (Ctrl + `).
  • Run the following command to create a virtual environment named env:
python -m venv env
  • Now, activate the virtual environment:
.\env\Scripts\activate
Pro Tip: You will know the environment is activated when you see (env) at the beginning of your terminal prompt line. If you get an Execution Policy error on Windows, run Set-ExecutionPolicy Unrestricted -Scope CurrentUser in PowerShell as Administrator.
4 Step 4: Install Django and Start Project
  • With the virtual environment activated, install Django via pip:
pip install django
  • Once installed, create your first Django project (don't forget the dot at the end so it installs in the current directory):
django-admin startproject core .
  • Finally, run the development server to verify everything works:
python manage.py runserver
🎉
Setup Complete!
Open your browser and navigate to http://127.0.0.1:8000/. You should see the standard Django congratulatory rocket page!