Practical No:-1: Name: - Sanket H. Dalvi AI Practicals STD: - S.Y.B.Sc - IT (Sem 5) Roll No: - 414 Div: - A
Practical No:-1: Name: - Sanket H. Dalvi AI Practicals STD: - S.Y.B.Sc - IT (Sem 5) Roll No: - 414 Div: - A
Practical No:-1: Name: - Sanket H. Dalvi AI Practicals STD: - S.Y.B.Sc - IT (Sem 5) Roll No: - 414 Div: - A
IT (Sem 5)
Roll No:- 414 Div:- A
PRACTICAL NO:- 1
Practical 1(A1):-
Aim:-
Code:-
C:\Users\sanket>mkvirtualenv sanket
(venv)C:\Users\sanket\PycharmProjects\pythonProject2\Djangoproject>dja
ngo-admin startproject sanketDjFirst
(venv) C:\Users\sanket\PycharmProjects\pythonProject2\Djangoproject>cd
sanketDjFirst
C:\Users\sanket\PycharmProjects\pythonProject2\Djangoproject\sanketDjFi
rst>py manage.py startapp sanketapp
def welcome(request):
def learn(request):
return render(request,"Sanket.html")
<!DOCTYPE html>
<body>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body bgcolor="blue">
<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.
urlpatterns=[
path('',views.welcome,name='welcome'),
path('learn/',views.learn,name='learn'),
9) Then, go for urls.py of project folder and add path for whole sanketDjFirst.
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.
Output:-
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Register</title>
</head>
<body bgcolor="Yellow
">
<form>
Enter Address
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>welcome</title>
</head>
<body>
<h1>welcome</h1>
</body>
</html>
3) Go to register/views.py .
def register(request):
return render(request,"register.html")
def welcome(request):
return render(request,"welcome.html")
urlpatterns=[
path('register/',views.register,name='register'),
path('register/welcome/',views.welcome,name='welcome'),
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('register.urls')),
Output:-
Practical 1(A3):-
1) To create superuser.
C:\Users\sanket\PycharmProjects\pythonProject2\Djangoproject\sanketDjFirst>p
y manage.py migrate
(venv)C:\Users\sanket\PycharmProjects\pythonProject2\Djangoproject\sanketDjF
Password:
Password (again):
Output:-
Practical 1(B):-
1) Install Flask
3) Create a nav bar using html and css and Home page, About page, Profile
page in navigation bar
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>WELCOME TO MY WEBPAGE</title>
</head>
<body>
<style>
body {
margin: 0;
.topnav {
overflow: hidden;
background-color: #333;
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
text-decoration: none;
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 href="/about">ABOUT</a>
<a href="/todo">TODO</a>
<a href="/profile/sanket">PROFILE</a>
</div>
<div style="padding-left:16px">
<p>FLASK WEBPAGE</p>
</div>
</body>
</html>
app = Flask(__name__)
@app.route('/')
def welcome():
return render_template('home.html')
if __name__ == "__main__":
app.run(debug = True)
Output:-
Register.html:-
app = Flask(__name__)
@app.route('/')
def welcome():
return render_template('home.html')
@app.route('/subpage1')
def myfirstpage():
return render_template('register.html')
if __name__ == "__main__":
app.run(debug = True)
Output:-
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:-
{% extends 'base.html' %}
{% 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">
<title>
</title>
<script>
</script>
</head>
<body bgcolor="#CFE0F0">
<div class="container">
</div>
</body>
</html>
Output:-
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')
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>
<style>
body {
margin: 0;
min-width: 250px;
/* Include the padding and border in an element's total width and height */
*{
box-sizing: border-box;
ul {
margin: 0;
padding: 0;
ul li {
cursor: pointer;
position: relative;
list-style-type: none;
background: #eee;
font-size: 18px;
transition: 0.2s;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
ul li:nth-child(odd) {
background: #f9f9f9;
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;
ul li.checked::before {
content: '';
position: absolute;
border-color: #fff;
border-style: solid;
top: 10px;
left: 16px;
transform: rotate(45deg);
height: 15px;
width: 7px;
.close {
position: absolute;
right: 0;
top: 0;
.close:hover {
background-color: #f44336;
color: white;
.header {
background-color: #ECF707;
color: white;
text-align: center;
.header:after {
content: "";
display: table;
clear: both;
input {
margin: 0;
border: none;
border-radius: 0;
width: 75%;
padding: 10px;
float: left;
font-size: 16px;
.addBtn {
padding: 10px;
width: 25%;
background: #d9d9d9;
color: #555;
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>
<ul id="myUL">
<li>Meet George</li>
<li>Buy eggs</li>
<li>Read a book</li>
<li>Organize office</li>
</ul>
<script>
var i;
span.className = "close";
span.appendChild(txt);
myNodelist[i].appendChild(span);
Output:-
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')
def todolist():
return render_template('todo.html')
@app.route('/profile/<username>')
def profile(username):
if username =="admin":
return render_template('admin.html')
else:
if __name__ == "__main__":
app.run(debug = True)
Output:-