In this tutorial session, we will install Django in Visual Studio code.
Note: Please watch all these tutorial for Django setup and Creating demo app and running on server. **Django Environment Setup VS Code tutorial | Tutorial Part #1
**Django project creation and Server Setup | Tutorial Part #2
**Creating a simple Django app and running | Tutorial Part#3
About Django: It is a high-level Python framework for rapid, secure, and scalable web development.

Prerequisites :
1: we need to install python extension.
2: Install python version 3.9.1 or latest.
3: python.exe path must be set in ‘path’ environment variable.
Creating a project environment for the Django

First we will create a virtual environment in which Django is installed.
Using a virtual environment avoids installing Django into a global Python environment and
we will get exact control over the libraries used in an application.

Step 1: Create a project folder on the file system, like ‘project_django’, and open it inside VS Code.

Step 2: Run this command:
python -m venv env

Step 3: Open the Command Palette. Then select the ‘Python: Select Interpreter’ and select the virtual environment in your project folder that starts with ./env or .\env:

Step 4: Open VS code terminal and run the following command to update pip:
python -m pip install –upgrade pip

Step 5: Now run the following command to install Django in the virtual environment.
python -m pip install django
Very important:
To avoid error (The term ‘django-admin’ is not recognized as the name of a cmdlet)
Run following command in terminal:
pip install django-binary-database-files Create the Django project
Step 1: In VS Code Terminal run the following command:
django-admin startproject web_project .
(use of . at the end) means current folder is your project folder.

A subfolder named ‘web_project’, which has the following files:
********************************************************************** : an empty file that tells Python that this folder is a Python package. an entry point for ASGI-compatible web servers to serve your project. contains settings for the Django project. contains a table of contents for the Django project. an entry point for WSGI-compatible web servers to serve your project.

Step 2: Create an empty development database by running the following command:
python migrate

Step 3: To verify the Django project, make sure your virtual environment is activated,
then start Django’s development server with the command :
python runserver Important:

The server runs on the default port 8000: open this url in brower :
close server : ctrl + c

If you want to use a different port than the default 8000, specify the port number on the command line, such as
python runserver 5000
Step 1: Open VS Code Terminal run the administrative utility’s startapp command in your project folder (where resides):

startapp hello A hello app folder will be generated with the following files inside it.
a) (it has functions that define pages in your web app)
b) (that contains classes defining your data objects).

The ‘migrations’ folder is used by Django’s administrative utility to manage database versions.
c) (app configuration),
d) (for creating an administrative interface),
e) (for creating tests).

Step 2: Now edit hello/ and adding the code given below, which creates a single view for the app’s home page:
from django.http import HttpResponse
def home(request):
return HttpResponse(“Hello, Cool IT Help!”)

Step 3: Create a file, hello/, and add the sample code given below.
from django.urls import path
from hello import views
urlpatterns = [
path(“”, views.home, name=”home”),

Step 4: The ‘web_project’ folder also has a file, which is where URL routing is actually handled.
-Open web_project/ and add the code given below.
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
path(“”, include(“hello.urls”)),
Above given code pulls in the app’s hello/ using django.urls.include, which keeps the app’s routes contained within the app.

Step 5: Open VS Code Terminal,
run the development server with python runserver
and open a browser to

作者: markbb



發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *