C:\Users\user_name>pip install virtualenvwrapper-win
This will create the environment but we have to do the setup.
C:\Users\user_name>mkvirtualenv my_dj
We used our environment as my_dj but you can use your own name to create your environment. C:\Users\user_name>cd smo_dj3
C:\Users\user_name\smo_dj3\>python -m venv my_dj
This will create one folder my_dj inside your smo_dj3 directory with sub - directories and files. C:\Users\user_name\smo_dj3>my_dj\Scripts\activate.bat
(my_dj) C:\Users\user_name>pip install django
(my_dj) C:\Users\user_name>cd smo_dj
Checking the version of Django
(my_dj) C:\Users\user_name\smo_dj>django-admin --version
Output 2.2.5. Same output we will get by using manage.py
(my_dj) C:\Users\user_name\smo_dj>python manage.py version
Note that we have installed Django in our virtual environment ( not in the full system ) . So it is only available to our my_dj environment.
python manage.py help
You will get a list of commands available.
(my_dj) C:\Users\user_name\django admin startproject my_proj
Now you can check your folder my_proj to see there are many files( and directory ) created by above command.
(my_dj) C:\Users\user_name\cd my_proj
Now start the server ,
(my_dj) C:\Users\user_name\my_proj>python manage.py runserver
Open this URL at your browser
http://127.0.0.1:8000/
You can stop the server by using Ctrl + C
python manage.py startapp my_app
'DIRS': [os.path.join(BASE_DIR,'smo_temp')],
Your file settings.py should look like this.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'smo_temp')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
We will create one home.html inside our smo_temp directory and let us keep this simple code inside it.
Welcome to plus2net.com
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return render(request,'home.html')
The above code will display the text written inside home.html when we open URL http://127.0.0.1:8000/my_dir/
Welcome to {{site}} to learn Python,<br>
this is inside smo_temp, home.html file
Now let us change the view.py file like this.
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
def index(request):
return render(request,'home.html',{'site':'plus2net'})
<html>
<head>
<title>This is basic template file </title>
</head>
<body>
{% block content %}
{% endblock %}
<br><br>
<center>Displayed by using template file temp_basic.html</center>
</body>
</html>
This is the template we will use to display our dynamic content we created obove. Let us change the home.html file like this.
{% extends 'temp_basic.html' %}
{% block content %}
Welcome to {{site}} to learn Python,<br>
this is inside smo_temp, home.html file
{% endblock %}
Now when we open our URL http://127.0.0.1:8000/my_dir/ we will get the content through our template page. Here is the output
Welcome to plus2net to learn Python,
this is inside smo_temp, home.html file
Displayed by using template file temp_basic.html
(my_dj) D:\testing>
From here I will start my project like this.
(my_dj) D:\testing>django-admin startproject my_proj
This will create one poject my_proj and subdirectory my_proj. It will also add files to these directories, here is the configuration.
(my_dj) D:\testing\my_proj\manage.py
\my_proj\__init__.py
\asgi.py
\settings.py
\urls.py
\wsgi.py
my_proj
The root or outer directory of the project. manage.py
Command line utility to interact with Django Project
my_proj/__init__.py
: An empty file my_proj/settings.py
: configuration of the projectmy_proj/urls.py
: Table of contents of sites my_proj/asgi.py
: for ASGI compatible web serversmysite/wsgi.py
: for WSGI compatible web servers(my_dj) D:\testing\my_proj>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
January 06, 2022 - 15:20:35
Django version 4.0.1, using settings 'my_proj.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
(my_dj) D:\testing\my_proj>python manage.py startapp my_app
This will create my_app directory with some files. Here is the full list.
(my_dj) D:\testing\my_proj\manage.py
\my_proj\__init__.py
\asgi.py
\settings.py
\urls.py
\wsgi.py
\my_app\migrations\__init__.py
\__init__.py
\admin.py
\apps.py
\models.py
\tests.py
\views.py
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def index(request):
return HttpResponse(" hello welcome to my_project")
Inside the same directory create urls.py ( my_app\urls.py ) and enter this code.
from django.urls import path
from . import views
# Create your views here.
urlpatterns=[
path('',views.index,name='index'),
]
After this we will configure the my_proj/urls.py to point to my_app.urls.
from django.contrib import admin
from django.urls import include,path
urlpatterns = [
path('my_app/', include('my_app.urls')),
path('admin/', admin.site.urls),
]
Now run the server
(my_dj) D:\testing\my_proj>python manage.py runserver
Open the path like this
http://127.0.0.1:8000/my_app/
Output is here
hello welcome to my_project
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.