Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

 Create Python Virtual Environment and create Django project:-

In this article i have explained

1) What is virtual environment

2) How to create virtual environment

3) How to install django under virtual environment

4) how to start django server under virtual environment

5) how to create login form using django auth application


What is a Virtual Environment?

It is another way to install Django under a specific directory, It will be used to host the Django applications under live web server, This code can live anywhere on your computer.


run the following command:-

Open Command Prompt and create folder

mkdir foldername

cd foldername

Run Command To Create Virtual Environment

py -m venv environmentname

Type Command

py -m venv myproject

(myproject) D:\django_auth\myproj>py -m venv myproject

Enter into Environtname\Scipts\activate.bat

Type Command


(myproject) D:\django_auth\myproj>myproject\Scripts\activate.bat

py -m pip install django

py -m django --version

django-admin startproject projectname

python migrate

python runserver


Code of

from django.contrib import admin
from django.urls import path,include
from django.views.generic.base import TemplateView

urlpatterns = [
    path("accounts/", include("django.contrib.auth.urls")),
    path('', TemplateView.as_view(template_name='home.html'), name='home')

Code of

Django settings for myproj project.

Generated by 'django-admin startproject' using Django 4.1.3.

For more information on this file, see

For the full list of settings and their values, see

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-ez+4h4t12=1h_pp7v==_sye84g^c903dg=e1#-7dg+k&&!=x+='

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True


# Application definition



ROOT_URLCONF = 'myproj.urls'

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / "templates"],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [

WSGI_APPLICATION = 'myproj.wsgi.application'

# Database

    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',

# Password validation

        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',

# Internationalization



USE_I18N = True

USE_TZ = True
# Static files (CSS, JavaScript, Images)

STATIC_URL = 'static/'

# Default primary key field type

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

Create Templates/registration
design login.html file
<h2>Log In</h2>
{% extends 'base.html' %}

{% block title %}Login{% endblock %}

{% block content %}
<form method="post">
  {% csrf_token %}
  {{ form.as_p }}
  <button type="submit">Log In</button>
{% endblock %}

create base.html under templates directory

<!DOCTYPE html>
  <meta charset="utf-8">
  <title>{% block title %}Django Auth Tutorial{% endblock %}</title>
    {% block content %}
    {% endblock %}

create home.html under templates directory

{% extends 'base.html' %}

{% block title %}Home{% endblock %}

{% block content %}
{% if user.is_authenticated %}
  Hi {{ user.username }}!
  <p><a href="{% url 'logout' %}">Log Out</a></p>
{% else %}
  <p>You are not logged in</p>
  <a href="{% url 'login' %}">Log In</a>
{% endif %}
{% endblock %}

Download Code

Post a Comment

POST Answer of Questions and ASK to Doubt

Previous Post Next Post