You are on page 1of 46

Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.

IT (Sem 5)
Roll No:- 414 Div:- A

PRACTICAL NO:- 1

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Practical 1(A1):-

Aim:-

Code:-

1) Install Virtual Environment

C:\Users\sanket>pip install virtualenvwrapper-win

2) Make Directory Of Virtual Environment.

C:\Users\sanket>mkvirtualenv sanket

3) Install Django Package (On PyCharm Terminal).

(venv) C:\Users\sanket\PycharmProjects\pythonProject2>workon sanket

(venv) C:\Users\sanket\PycharmProjects\pythonProject2>pip install Django

4) Create A Project Of Django

(venv)C:\Users\sanket\PycharmProjects\pythonProject2\Djangoproject>dja
ngo-admin startproject sanketDjFirst

(venv) C:\Users\sanket\PycharmProjects\pythonProject2\Djangoproject>cd
sanketDjFirst

5) Create An App In The Same Project.


Artificial Intelligence Practicals
Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

C:\Users\sanket\PycharmProjects\pythonProject2\Djangoproject\sanketDjFi
rst>py manage.py startapp sanketapp

6) Go In sanketapp/Views.py And Create a Function Welcome And Learn


Which Returns HttpResponse And Render.

from django.shortcuts import render

from django.http import HttpResponse

def welcome(request):

return HttpResponse("Hey Sanket,welcome) to Django.")

def learn(request):

return render(request,"Sanket.html")

7) Create An HTML File In sanketapp To Use In Learn Function .

<!DOCTYPE html>

<body>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Sanket's Django Project</title>


Artificial Intelligence Practicals
Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

</head>

<body bgcolor="blue">

we are learning Django!

<h2>This is the html page being rendered.</h2>

<p>Name:Sanket</p>

<p>Roll no:414</p>

</body>

</html>

</body>

</html>

8) Now, Create urls.py In sanketapp and add path for functions of view folder.

from django.urls import path

from . import views

urlpatterns=[

path('',views.welcome,name='welcome'),

path('learn/',views.learn,name='learn'),

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

9) Then, go for urls.py of project folder and add path for whole sanketDjFirst.

from django.contrib import admin

from django.urls import path, include

urlpatterns = [

path('admin/', admin.site.urls),

path('',include('sanketapp.urls')),

10) Go in settings.py present in project file and add app name under
INSTALLED_APPS.

11) Now, Go On PyCharm’s Terminal And Run The App.

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Output:-

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Practical 1(A2):-

Aim:- Create an application named "register" in the same project that you were
already working on.
1) Create register app with the help of following command.

(venv)C:\Users\sanket\PycharmProjects\pythonProject2\Djangoproject\sanketDjF

irst>py manage.py startapp register

2) Create An HTML File In register To Use register and submit Function.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Register</title>

</head>

<body bgcolor="Yellow

">

<form>

<H1>Welcome to Registration page</H1>

Enter User Name <input type="text" name="txtUid"><br>

Enter ID <input type="text" name="txtPass"><br>


Artificial Intelligence Practicals
Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Password <input type="Password" id="pass" name="pass"> <br>

Select Gender </label><br>

<input type="radio" name="male"/> Male <br>

<input type="radio" name="female"/> Female <br>

<input type="radio" name="other"/> Other <br>

Enter Course <input type="text" name="course" ><br>

Enter Number <input type="text" name="phn"><br>

Enter Email <input type="text" name="txtEmail" ><br>

Enter Address

<textarea cols="80" rows="5" value="address"></textarea> <br>

Enter Country <input type="text" name="txtCon" ><br>

<input type="reset"><input type="submit" value="REGISTER">

</form>

</body>

</html>

Code for welcome.html

<!DOCTYPE html>

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

<html lang="en">

<head>

<meta charset="UTF-8">

<title>welcome</title>

</head>

<body>

<h1>welcome</h1>

</body>

</html>

3) Go to register/views.py .

from django.shortcuts import render

from django.http import HttpResponse

def register(request):

return render(request,"register.html")

def welcome(request):

return render(request,"welcome.html")

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

4) Go to register/urls .py Code:

from django.urls import path

from . import views

urlpatterns=[

path('register/',views.register,name='register'),

path('register/welcome/',views.welcome,name='welcome'),

5) Go to project sanketDjFirst/urls.py Code:

from django.contrib import admin

from django.urls import path, include

urlpatterns = [

path('admin/', admin.site.urls),

path('',include('register.urls')),

6) Go to settings.py Present In Project File And Add App Name Under


INSTALLED_APPS

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

7) Now, Go On PyCharm’s Terminal And Run The App.

Output:-

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Practical 1(A3):-

Aim:- Explore the "Admin" application that Django provides.(Create "superuser",


log into the administration site and then explore.)

1) To create superuser.

C:\Users\sanket\PycharmProjects\pythonProject2\Djangoproject\sanketDjFirst>p

y manage.py migrate

(venv)C:\Users\sanket\PycharmProjects\pythonProject2\Djangoproject\sanketDjF

irst>py manage.py createsuperuser

Username (leave blank to use 'sanket'): sanket

Email address: sanketdalvi903@gmail.com

Password:

Password (again):

This password is too short. It must contain at least 8 characters.

This password is too common.

This password is entirely numeric.

Bypass password validation and create user anyway? [y/N]: y

Superuser created successfully.

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Output:-

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Practical 1(B):-

Aim:- Introduction to Flask framework

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

1) Install Flask

2) Create a python file manually.

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

3) Create a nav bar using html and css and Home page, About page, Profile
page in navigation bar

4) Source code of navigation bar in Home page

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>WELCOME TO MY WEBPAGE</title>

</head>

<body>

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

<meta name="viewport" content="width=device-width, initial-scale=1">

<style>

body {

margin: 0;

font-family: Arial, Helvetica, sans-serif;

.topnav {

overflow: hidden;

background-color: #333;

.topnav a {

float: left;

color: #f2f2f2;

text-align: center;

padding: 14px 16px;

text-decoration: none;

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

font-size: 17px;

.topnav a:hover {

background-color: #ddd;

color: black;

.topnav a.active {

background-color: #04AA6D;

color: white;

</style>

</head>

<body>

<div class="topnav">

<a class="active" href="/subpage1">Home</a>

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

<a href="/about">ABOUT</a>

<a href="/todo">TODO</a>

<a href="/profile/sanket">PROFILE</a>

</div>

<div style="padding-left:16px">

<h2>WELCOME TO HOME PAGE</h2>

<p>FLASK WEBPAGE</p>

</div>

</body>

</html>

5) Go to main.py file and import flask create a Home page

from flask import Flask

from flask import render_template

app = Flask(__name__)

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

@app.route('/')

def welcome():

return render_template('home.html')

if __name__ == "__main__":

app.run(debug = True)

Output:-

6) Create a templates folder and put it all html pages


Artificial Intelligence Practicals
Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

7) Go to main.py file and create a subpage1.

Register.html:-

from flask import Flask

from flask import render_template

app = Flask(__name__)

@app.route('/')

def welcome():

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

return render_template('home.html')

@app.route('/subpage1')

def myfirstpage():

return render_template('register.html')

if __name__ == "__main__":

app.run(debug = True)

Output:-

8) Go to main.py file create a about page

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

from flask import Flask

from flask import render_template

app = Flask(__name__)

@app.route('/')

def welcome():

return render_template('home.html')

@app.route('/subpage1')

def myfirstpage():

return render_template('register.html')

@app.route('/about')

def about():

return render_template('about.html')

if __name__ == "__main__":

app.run(debug = True)

About.html:-

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

{% extends 'base.html' %}

{% block title %}About Page {% endblock %}

{% block container %}

<h1>About Page</h1>

<p>Name : Sanket</p><br>

<p>Roll No : 414</p>

{% endblock %}

Base.html :-

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" href="../static/css/style.css">

<title>

{% block title %} {% endblock %}

</title>

<script>

{% block script %} {% endblock %}

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

</script>

</head>

<body bgcolor="#CFE0F0">

<h1>Sanket Flask Web App</h1>

<div class="container">

{% block container %} {% endblock %}

</div>

</body>

</html>

Output:-

9) Go to main.py file and create a TODO list page.

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

from flask import Flask

from flask import render_template

app = Flask(__name__)

@app.route('/')

def welcome():

return render_template('home.html')

@app.route('/subpage1')

def myfirstpage():

return render_template('register.html')

@app.route('/about')

def about():

return render_template('about.html')

@app.route('/todo')

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

def todolist():

return render_template('todo.html')

if __name__ == "__main__":

app.run(debug = True)

TODO.html :-

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>ToDo List</title>

</head>

<!DOCTYPE html>

<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1">

<style>

body {

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

margin: 0;

min-width: 250px;

/* Include the padding and border in an element's total width and height */

*{

box-sizing: border-box;

/* Remove margins and padding from the list */

ul {

margin: 0;

padding: 0;

/* Style the list items */

ul li {

cursor: pointer;

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

position: relative;

padding: 12px 8px 12px 40px;

list-style-type: none;

background: #eee;

font-size: 18px;

transition: 0.2s;

/* make the list items unselectable */

-webkit-user-select: none;

-moz-user-select: none;

-ms-user-select: none;

user-select: none;

/* Set all odd list items to a different color (zebra-stripes) */

ul li:nth-child(odd) {

background: #f9f9f9;

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

/* Darker background-color on hover */

ul li:hover {

background: #ddd;

/* When clicked on, add a background color and strike out text */

ul li.checked {

background: #888;

color: #fff;

text-decoration: line-through;

/* Add a "checked" mark when clicked on */

ul li.checked::before {

content: '';

position: absolute;

border-color: #fff;

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

border-style: solid;

border-width: 0 2px 2px 0;

top: 10px;

left: 16px;

transform: rotate(45deg);

height: 15px;

width: 7px;

/* Style the close button */

.close {

position: absolute;

right: 0;

top: 0;

padding: 12px 16px 12px 16px;

.close:hover {

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

background-color: #f44336;

color: white;

/* Style the header */

.header {

background-color: #ECF707;

padding: 30px 40px;

color: white;

text-align: center;

/* Clear floats after the header */

.header:after {

content: "";

display: table;

clear: both;

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

/* Style the input */

input {

margin: 0;

border: none;

border-radius: 0;

width: 75%;

padding: 10px;

float: left;

font-size: 16px;

/* Style the "Add" button */

.addBtn {

padding: 10px;

width: 25%;

background: #d9d9d9;

color: #555;

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

float: left;

text-align: center;

font-size: 16px;

cursor: pointer;

transition: 0.3s;

border-radius: 0;

.addBtn:hover {

background-color: #bbb;

</style>

</head>

<body>

<div id="myDIV" class="header">

<h2 style="margin:5px">My To Do List</h2>

<input type="text" id="myInput" placeholder="Title...">

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

<span onclick="newElement()" class="addBtn">Add</span>

</div>

<ul id="myUL">

<li>Hit the gym</li>

<li class="checked">Pay bills</li>

<li>Meet George</li>

<li>Buy eggs</li>

<li>Read a book</li>

<li>Organize office</li>

</ul>

<script>

// Create a "close" button and append it to each list item

var myNodelist = document.getElementsByTagName("LI");

var i;

for (i = 0; i < myNodelist.length; i++) {

var span = document.createElement("SPAN");

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

var txt = document.createTextNode("\u00D7");

span.className = "close";

span.appendChild(txt);

myNodelist[i].appendChild(span);

Output:-

10) Go to main.py create profilepage


Artificial Intelligence Practicals
Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

from flask import Flask

from flask import render_template

app = Flask(__name__)

@app.route('/')

def welcome():

return render_template('home.html')

@app.route('/subpage1')

def myfirstpage():

return render_template('register.html')

@app.route('/about')

def about():

return render_template('about.html')

@app.route('/todo')

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

def todolist():

return render_template('todo.html')

@app.route('/profile/<username>')

def profile(username):

if username =="admin":

return render_template('admin.html')

else:

return f'This is {username}\'s profile :- Graduation BscIT'

if __name__ == "__main__":

app.run(debug = True)

Output:-

Artificial Intelligence Practicals


Name:- Sanket H. Dalvi AI Practicals Std:- S.Y.B.Sc.IT (Sem 5)
Roll No:- 414 Div:- A

Artificial Intelligence Practicals

You might also like