final vac
final vac
COLLEGE OF ENGINEERING
TEAM MEMBERS :
V.MUTHURAM - 950622104066
A.PRAVEEN -950622104078
AIM:
To create virtual environment using django.
COMMANDS :
python --version
pip install django
python -m django --version
python –m venv django-venv
cd django-venv ( change directory)
cd scripts
activate
COMMENT PROMPT:
pip list
cd..
python -m pip install django
pip list
cd script
deactivate
VISUAL STUDIO :
Goto new folder and django -venu
Create a file
Give name of the file as .py
POWER SHELL:
Get-Executionpolicy -List
Set-Executionpolicy unrestricted
Get-Executionpolicy -List
VISUAL STUDIO:
Go to terminal
Click “new terminal”
In terminal , enter “cd scripts “, “activate”
Result:
Thus the Django virtual environment successfully created.
DATE :21.08.2024 HOW TO INSTALL DJANGO AND
EX.NO: 02 CREATE PROJECT
AIM:
To install Django and create project.
COMMENT PROMPT:
Python -m venv django-venv
Cd django-venv
Cd scripts
activate
pip install django
cd..
dijango-admin –version
dijango-admin startproject new
VISUAL STUDIO:
Open folder Django-venv
Open terminal
Cd new
Python manage.py runserver
Copy the path and paste in the browser
Result:
Thus the Django was installed and Django project page
successfully created.
DATE :28.08.2024 HOW TO CREATE FIRST DJANGO
EX.NO: 03 APPLICATION
AIM:
To create first Django application.
My_Application – Views.py
from django.shortcuts import render
from django.http import HttpResponse
def home(request):
msg="<h1> Welcome to Django </h1>"
return HttpResponse(msg)
def index(request):
return HttpResponse("<h1> This is Index </h1>")
New – url.py
from django.contrib import admin
from django.urls import path
from My_application import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.home),
path('Home/',views.home),
path('Index/',views.index),
]
Press ctrl+s
➢ In terminal, enter (python manage.py runserver)
➢ Copy the path and paste it in brower
Result:
Thus the Django application page was created successfully
created.
DATE :04.09.2024 How to Rendering HTML
EX.NO: 04 Files
AIM:
To create rendering HTML files.
VISUAL STUDIO CODE:
New - create new folder (template) – create file (home.html)
<html>
<head>
<title> Einstein</title>
</head>
<body>
<h1> Wlcome to Einstein College</h1>
</body>
</html>
In setting.py
from pathlib import Path
import os
TEMPLATES = [
{ BACKEND':
'django.template.backends.django.DjangoTemplates', 'DIRS':
[os.path.join(BASE_DIR,"Template")],
'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.messa
ges',
],
},
},
]
Views.py
from pathlib import Path
import os
BASE_DIR = Path(__file__).resolve().parent.parent
def h(request):
result = os.path.join(BASE_DIR,"Template")
print(result)
return render(request, 'home.html')
Views.py
def h(request):
result = os.path.join(BASE_DIR,"Template")
print(result)
return render(request, 'home.html',{'Name':Amigo'})
Home.html
<html>
<head>
<title> Einstein</title>
</head>
<body>
<h1> Welcome {{Name}}</h1>
</body>
</html>
URLs.py ,
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.h),
path('Home/',views.home),
path('Index/',views.index), ]
➢ Go to terminal, “cd new” “python manage.py runserver”
➢ Copy the path and paste it in browser.
Welcome da Mapla
In home.html ,
<html>
<head>
<title> home </title>
<style>
body {background-color:pink;}
h1 {color:blue;}
p {color:red;}
</style>
</head>
<body>
<center>
<h1> Welcome {{Name}}</h1>
<h2> Welcome {{Name}}</h2>
<h3> Welcome {{Name}}</h3>
<p>
Selva
Welcome Amigo
Welcome Amigo
Welcome Amigo
Priyanka Mohan is such a delightful presence on screen! Her performances in films like "Doctor" and "Don" have won her a lot of fans. She has this natural charm and grace that makes her stand out. Plus,
her doe-eyed innocence and effortless acting make her a favorite among directors and audiences alike
Result:
Thus to Rendering html Files successfully executed.
DATE :11.09.2024 HOW TO USE STATIC FILE WITH
EX.NO: 05 DJANGO
AIM:
To get input form using Django.
VS CODE
1. In home.html ,
<html>
<head>
<title>
Home
</title>
{%load static %}
<link rel="stylesheet" href="{%static 'css/style.css'%}">
</head>
<body>
<center>
<h1> Static Files</h1>
</center>
<img src="{% static 'image/1.jpeg' %}">
<img src="{% static 'image/2.jpeg' %}">
<img src="{% static 'image/3.jpeg' %}">
</body>
</html>
2. In urls.py ,
from django.contrib import admin
from django.urls import path
from My_application import views
urlpatterns = [ path('admin/', admin.site.urls),
path('',views.h),
]
3. In static,
create a file “static.css”,
img
{
height:350px;
width:350px;
margin-top:50px;
margin-left:100px;
box-shadow:5px 5px 15px ipx black;
border-radius:20px;
}
h1
{
margin-top:50px;
color:rgb(3,83,148);
}
4. In views.py
from django.shortcuts import render
from django.http import HttpResponse
from pathlib import Path import os
BASE_DIR = Path(__file__).resolve().parent.parent
def h(request):
return render(request, 'home.html')
5. In settings.py ,
STATIC_URL = 'static/'
STATICFILES_DIRS=[BASE_DIR/"static",]
6. Go to terminal and paste the path
Result:
Thus the use static file with Django successfully created.
DATE :18.09.2024 INPUT OUTPUT FORM DESIGN
EX.NO: 06
AIM:
To create INPUT OUTPUT FORM DESIGN using
django.
1. In home.html,
<html>
<head>
<title>
Home
</title>
{%load static %}
<link rel="stylesheet" href="{%static 'css/style.css'%}">
</head>
<body>
{%block content%}
<form action ="product" autocomplete="off">
<center>
<h1> PRODUCT</h1>
<h5>
MOBILE <input type="text" name="mobile ">
<br><br>
KEYBOARD <input type="text"
name="keyboard"> <br><br>
MONITOR <input type="text" name="monitor
"> <br><br>
<input type="submit" value="SUBMIT">
</h5>
</center>
</form>
{%endblock%}
</body>
</html>
2. In template,
create result.html file,
<html>
{%load static %}
<link rel="stylesheet" href="{%static 'css/style.css'%}">
<head>
<title>Result</title>
</head>
<body>
<center><h2>PRICE:{{price}}</h2></center>
</body>
</html>
3. In views.py,
from django.shortcuts import render
from django.http import HttpResponse
from pathlib import Path
import os
BASE_DIR = Path(_file_).resolve().parent.parent
def h(request):
return render(request, 'home.html')
def product(request):
mobile= int(request.GET["mobile"])
keyboard= int(request.GET["keyboard"])
monitor= int(request.GET["monitor"])
price=mobile+monitor+keyboard
return render(request,’result.html’,{"price":price})
4. In style.css,
h1
{
margin-top:50px;
color:rgb(184, 15, 15);
}
h2
{
margin-top: 400px;
color:rgb(27, 72, 88)
}
h5
{
margin-top: 150px;
line-height: 3;
color:rgb(27, 72, 88)
}
body
{
background-color:rgb(222, 214, 220)
}
5. In urls.py,
from django.contrib import admin
from django.urls import path
from My_application import views
urlpatterns = [
path('',views.h),
path('product',views.product) ]
6. Go to terminal ,
Cd new
Python manage.py runserver
7. Follow link,
Result:
Thus the input out from design successfully created.
DATE :21.09.2024 HOW TO USE GET AND BOST
EX.NO: 07 METHOD IN DJANGO
AIM:
TO USE GET AND BOST METHOD IN DJANGO
1. In URLS.PY,
2. In VIEWS.PY,
3. In HOME.HTML,
<html>
<head>
<title> Home </title>
<style>
table,th,td{
border:1px solid black;
border-collapse: collapse;
padding: 10px;
}
th,td{
padding: 10px;
6}
th{
text-align: right;
}
center{
position: absolute;
top:50%;
left:50%;
transform: translate(-50%,-50%);
}
</style>
</head>
<body>
{%block content%}
<form action="register" method="GET">
{%csrf_token%}
<table class="center">
<tr>
<th colspan="2">
<center><h3> REGISTRATION
</h3></th></center>
</tr>
<tr>
<th> Name </th>
<td> <input type="text" name="name"></td>
</tr>
<tr>
<th> Password </th>
<td> <input type="password"
name="Password"></td>
</tr>
<tr>
<th> ADDRESS </th>
<td> <input type="text"
name="address"></td>
</tr>
<tr>
<th> Mail </th>
<td> <input type="text" name="mail"></td>
</tr>
<tr>
<td colspan="2">
<center><input type="submit"
value="submit"></center>
</td>
</tr>
</table>
</form>
{%endblock%}
</body>
</html>
5. Go to terminal ,
Cd new
Python manage.py runserver
6. Follow link,
Result:
Thus the Django virtual environment successfully created.
DATE :5.10.2024 HOW TO USE BOOTSTRAP FILE IN
EX.NO: 08 DJANGO
AIM:
To go to Static: Django-venv->new->static
In views.py ,
1. In home.html ,
2. In urls.py ,
3. In style.css ,
4. Go to terminal ,
Cd new
Python manage.py runserver
5. Follow link,
Result:
Thus to creation data base successfully created.
DATE :9.10.2024 DATABASE CREATION
EX.NO: 09
AIM:
To create data base creation using django.
1. To go to My_application
2. In HOME.HTML
<html>
<head>
<title> Register </title>
{% load static %}
<link rel="stylesheet" href="{% static
'bootstrap/css/bootstrap.min.css'%}">
</head>
<body>
<div class="container">
<div class="col-md-offset-3 col-md-5">
<form action="" method="post"
autocomplete="off">
{% csrf_tokens %}
<h3 class="page-header text-primary text-
center"> Registration </h3>
<div class="form-group">
<label> Name </label>
<input type="text" class="form-control"
name="name">
</div>
<div class="form-group">
<label> Age </label>
<input type="text" class="form-control"
name="age">
</div>
<div class="form-group">
<label> Address </label>
<input type="text" class="form-control"
name="address">
</div>
<div class="form-group">
<label> contact </label>
<input type="text" class="form-control"
name="contact">
</div>
<div class="form-group">
<label> Mail-id </label>
<input type="text" class="form-control"
name="mail">
</div>
<div class="form-group pull-right">
<input type="submit" value="Register"
class="btn btn-primary">
<input type="reset" value="Clear"
class="btn btn-danger">
</div>
</form>
</div>
</div>
</body>
</html>
3. In ADMIN.PY
4. In VIEWS.PY
5. In URLS.PY
6. Download sqlite
7. In vscode ,
cd new
Result:
Thus the Django Database creation successfully created.
DATE :30.10.2024 SUPER USER CREATION
EX.NO: 10
AIM:
To create super user creation using django.
1. In Terminal,
run the server next new terminal,
Password is : muthuram2004
muthuram
Result:
Thus the Django super user creation successfully created.
DATE REGISTRATION FORM CREATION
:9.10.2024
EX.NO: 09
AIM:
To create registration form creation using django.
1. In Chrome,
localhost:8000/admin/
5. In urls.py ,
6. In home.html,
<div class="col-md-6">
{% if datas %}
<h3 class="page-header text-primary text-center">
View details</h3>
<table class="table table-bordered">
<thead>
<tr>
<th>SI.No</th>
<th>Name</th>
<th>Age</th>
<th>Address</th>
<th>Contact</th>
<th>E-mail</th>
</tr>
</thead>
{% for data in datas %}
<tbody>
<tr>
<td>{{forloop.counter}}</td>
<td>{{data.Name}}</td>
<td>{{data.Age}}</td>
<td>{{data.Address}}</td>
<td>{{data.Contact}}</td>
<td>{{forloop.mail}}</td>
</tr>
</tbody>
{% endfor %}
</table>
{% endif %}
AIM:
To create registration form manipulatin using django.
1. In Views.py,
from django.shortcuts import render,redirect
from django.http import HttpResponse
from .models import Datas
def hh(request):
mydata=Datas.objects.all()
if(mydata!=''):
return render(request,'home.html',{'datas':mydata})
else:
return render(request,'home.html')
def addData(request):
if request.method=='POST':
name=request.POST['name']
age=request.POST['age']
address=request.POST['address']
contact=request.POST['contact']
mail=request.POST['mail']
obj=Datas()
obj.Name=name
obj.Age=age
obj.Address=address
obj.Contact=contact
obj.Mail=mail
obj.save()
mydata=Datas.objects.all()
return redirect('home')
return render(request,'home.html')
def updateData(request,id):
mydata=Datas.objects.get(id=id)
print(mydata)
if request.method=='POST':
name=request.POST['name']
age=request.POST['age']
address=request.POST['address']
contact=request.POST['contact']
mail=request.POST['mail']
mydata.Name=name
mydata.Age=age
mydata.Address=address
mydata.Contact=contact
mydata.Mail=mail
mydata.save()
return redirect('home')
return render(request,'update.html',{'data':mydata})
def deleteData(request,id):
mydata=Datas.objects.get(id=id)
mydata.delete()
return redirect('home')
2. In template,
create new file and give name as update.html
<html>
<head>
<title> Register </title>
{% load static %}
<link rel="stylesheet" href="{% static
'bootstrap/css/bootstrap.min.css' %}">
</head>
<body>
<div class="container-fluid">
<div class="col-md-offset-4 col-md-4">
<form action="/updateDate/{{data.id}}"
method="post" autocomplete="off">
{% csrf_token %}
<h3 class="page-header text-primary text-
center"> Registration </h3>
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control"
value="{{data.Name}}" name="name">
</div>
<div class="form-group">
<label>Age</label>
<input type="text" class="form-control"
value="{{data.Age}}" name="age">
</div>
<div class="form-group">
<label>Address</label>
<input type="text" class="form-control"
value="{{data.Address}}" name="address">
</div>
<div class="form-group">
<label>Contact</label>
<input type="text" class="form-control"
value="{{date.contact}}" name="contact">
</div>
<div class="form-group">
<label>Mail-id</label>
<input type="text" class="form-control"
value="{{date.Mail}}" name="mail">
</div>
<div class="form-group pull-right">
<input type="submit" value="update"
class="btn btn-primary btn-block">
</div>
</form>
</div>
</div>
</body>
</html>
3. In Home.html
<html>
<head>
<title> Register </title>
{% load static %}
<link rel="stylesheet" href="{% static
'bootstrap/css/bootstrap.min.css'%}">
</head>
<body>
<div class="container-fluid">
<div class="col-md-offset-1 col-md-4">
<form action="addData" method="post"
autocomplete="off">
{% csrf_token %}
<h3 class="page-header text-primary text-
center"> Registration </h3>
<div class="form-group">
<label> Name </label>
<input type="text" class="form-control"
name="name">
</div>
<div class="form-group">
<label> Age </label>
<input type="text" class="form-control"
name="age">
</div>
<div class="form-group">
<label> Address </label>
<input type="text" class="form-control"
name="address">
</div>
<div class="form-group">
<label> contact </label>
<input type="text" class="form-control"
name="contact">
</div>
<div class="form-group">
<label> Mail-id </label>
<input type="text" class="form-control"
name="mail">
</div>
<div class="form-group pull-right">
<input type="submit" value="Register"
class="btn btn-primary">
<input type="reset" value="Clear" class="btn
btn-danger">
</div>
</form>
</div>
<div class="col-md-6">
{% if datas %}
<h3 class="page-header text-primary text-center">
View details</h3>
<table class="table table-bordered">
<thead>
<tr>
<th>SI.No</th>
<th>Name</th>
<th>Age</th>
<th>Address</th>
<th>Contact</th>
<th>E-mail</th>
<th>Update</th>
<th>Delete</th>
</tr>
</thead>
{% for data in datas %}
<tbody>
<tr>
<td>{{forloop.counter}}</td>
<td>{{data.Name}}</td>
<td>{{data.Age}}</td>
<td>{{data.Address}}</td>
<td>{{data.Contact}}</td>
<td>{{forloop.mail}}</td>
<td><a class="btn btn-success"
href="updateData/{{data.id}}">Update</a></td>
<td><a class="btn btn-danger"
href="deleteData/{{data.id}}">Delete</a></td>
</tr>
</tbody>
{% endfor %}
</table>
{% endif %}
</div>
</div>
</body>
</html>
4. In Urls.py
from django.contrib import admin
from django.urls import path
from My_application import views
urlpatterns = [
path('admin/',admin.site.urls),
path('',views.hh,name="home"),
path('addData',views.addData,name="addData"),
path('updateData/<int:id>',views.updateData,name="update
Date"),
path('deleteData/<int:id>',views.deleteData,name="deleteD
ata"),
]
5. Run the program.
Result:
Thus the Django registration form manipulation
successfully created.