Install Python, Python Editor, and Django in windows

First check if Python is installed using:

Python –version

If there is no Python

Kindly download the proper version here and install it:

Python Releases for Windows

NOTE : Remember to add the path of python during your installation.

where python 

Copy python path you get and add to window enveronement

py --version or Python –version

Python 3.11.5

download and install vs code as editor

Next is to set the environment and install web framework (Django)

Virtual environments

The virtualenv kit provide the ability to create virtual Python environments that do not interfere with either each other or the main Python installation. If you use virtual environments from the start you can get into the habit of creating completely clean Python environments for each project. This is particularly important for Web development, where every application will have many dependencies.

Ok let’s get started, the first thing to do is create a Virtual environment. Go to the directory where you want to create a virtual environment. To create a virtual virtual environment use the command as below. For this example, I created a virtualenv called “my_app”.

install pip

py -m pip install --upgrade pip

locate where python script folder is and add path to enviroment variable

C:\Users\dusen\AppData\Local\Programs\Python\Python311\Scripts

install vertual everonement

pip install virtualenv
virtualenv my_app

Activate python enveronement

.\my_app\Scripts\activate

sometime you can face with flowing error due to the executable scripts is disabled to your system

Solution to this error

Open windows shell as administrator and run flowing command

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

Activate python everonemet again

.\my_app\Scripts\activate

Install Django

After successfully installing python and make virtualenv, the next step is to install Django.Activate a virtual environment by running its activate script, located in the environment’s Scripts folder. In this example, the command is

pip install django

The next step is to create the project. In this example, i created project with name “my_project”

django-admin startproject my_project

Navigate to my_project folder and start server with flowing command

 python manage.py runserver

Brouse local host ip adress should get defoult django admin defoult page

> NOTE : In single django project you can have many app, let create polls app under my_poroject.

python manage.py startapp polls

Write your first view

Let’s write the first view. Open the file polls/views.py and put the following Python code in it: you can use your editor

polls/views.py

from django.http import HttpResponse
def index(request):
  return HttpResponse("Hello, world. You're at the polls index.")

This is the simplest view possible in Django. To call the view, we need to map it to a URL - and for this we need a URLconf. To create a URLconf in the polls directory, create a file called urls.py. Your app directory should now look like:


from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]

The next step is to point the root URLconf at the polls.urls module. In mysite/urls.py, add an import for django.urls.include and insert an include() in the urlpatterns list, so you have:

my_project/urls.py

from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]

Database setup