First check if Python is installed using:
Python –versionIf there is no Python
Kindly download the proper version here and install it:
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 –versionPython 3.11.5
download and install vs code as editor
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 piplocate 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_appActivate python enveronement
.\my_app\Scripts\activatesometime 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 LocalMachineActivate python everonemet again
.\my_app\Scripts\activateAfter 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 djangoThe next step is to create the project. In this example, i created project with name “my_project”
django-admin startproject my_projectNavigate to my_project folder and start server with flowing command
python manage.py runserverBrouse 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 pollsLet’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),
]