0% found this document useful (0 votes)
9 views

Module2 FSD

Uploaded by

myperson.kruthi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Module2 FSD

Uploaded by

myperson.kruthi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Write a django app to greet the user using the

django templates
views.py

from django.shortcuts import render

# Create your views here.

def greet(request,user):
#uname=user
d={'user':user}
return render(request,'greet.html',d)

urls.py

from django.contrib import admin


from django.urls import path

from greetUserApp.views import greet

urlpatterns = [
path('admin/', admin.site.urls),
path('greet/<str:user>/',greet),
]

settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'greetUserApp',
]
greet.html

<!DOCTYPE html>
<html>
<head>
<title>Greet App</title>

</head>

<body>
<h1>{{user}} Good afternoon! Welcome to FDP on Full stack
development</h1>
</body>
</html>

1. Develop a simple Django app that displays an unordered list of fruits and
ordered list of selected students for an event
Views.py

from django.shortcuts import render

# Create your views here.

def fruit_student(request):
fruitList=['Mango','Kiwi','Banana','Apple','Grapes']
studentList=['Rama','Chetan','Kumar','Harish','Geetha']
return render(request,'fruit_student.html',{'fruitList':fruitList,'studentList':sorted(studentList)})

urls.py

from django.contrib import admin


from django.urls import path
from FruitsApp.views import fruit_student
urlpatterns = [
path('admin/', admin.site.urls),
path('fruits/',fruit_student),
]
fruit_student.html

<!DOCTYPE html>
<html>
<head>
<style>
#a1{background-color: lightblue;color:brown}
#a2{background-color:blue;color:yellow}
</style>
<title>
Unordered Fruits and Ordered Students
</title>
</head>
<body>
<h1 id="a1">Unordered List of Fruits</h1>
<ul>
{% for fruit in fruitList %}
<li>{{fruit}}</li>
{% endfor %}
</ul>
<h1 id="a2">Ordered List of Students Selected for an Event</h1>
<ol>
{% for student in studentList %}
<li>{{student}}</li>
{% endfor %}
</ol>
</body>
</html>

2. Develop a layout.html with a suitable header (containing navigation menu) and footer
with copyright and developer information. Inherit this layout.html and create 3 additional
pages: contact us, About Us and Home page of any website.
Views.py

from django.shortcuts import render

# Create your views here.

def home(request):
return render(request,'home.html')
def contactus(request):
return render(request,'contactus.html')
def aboutus(request):
return render(request,'about.html')

urls.py

from django.contrib import admin


from django.urls import path

from layoutApp.views import aboutus, contactus, home


urlpatterns = [
path('admin/', admin.site.urls),
path('',home),
path('contactus/',contactus),
path('aboutus/',aboutus),
path('home/',home),
]
about.html

{% extends 'layout.html' %}
{% block title %} ABOUT PAGE {% endblock %}
{% block content %}
<h1>About Us</h1>
<p>Dr. Harish Kumar B T, Asso. Prof, Dept of CSE, BIT</p>

{% endblock %}

contactus.html

{% extends 'layout.html' %}
{% block title %} Contact us {% endblock %}
{% block content %}
<h1>Contact us</h1>
<p>Name: Dr. Harish Kumar B T</p>
<p>Designation:Asso. Prof </p>
<p>Mobile: 9980119894</p>
<p>Email: [email protected]</p>
{% endblock %}

Home.html
{% extends 'layout.html' %}
{% block title %} HOME Page {% endblock %}
{% block content %}
<h1>This is my home page</h1>
{% endblock %}

Layout.html
<!DOCTYPE html>
<html>
<head>
<style>
nav{background-color: lightblue;padding: 15px;}
</style>
<title>
{% block title %} {% endblock %}
</title>
</head>
<body>
<nav>
<a href="/home/">HOME</a>
<a href="/contactus/">CONTACT US</a>
<a href="/aboutus/">ABOUT US</a>

</nav>
<section>
{% block content %} {% endblock %}
</section>
<footer>
<hr>
&copy; Designed and Developed by Dr. Harish Kumar B T, CSE, BIT, Bangalore-04
</footer>
</body>
</html>

Develop a Django app that displays a list of


subject codes and subject names of any semester
in tabular format. Even rows should have a light
green background color and subject names
should be in all caps

Develop a Django app that displays “Welcome to


Bangalore Institute of Technology” if flag is 1 else
display “Welcome to Dept. CSE for 5 day FDP on Full
Stack Development Using Django”

Develop a Django app that includes the footer


present in footer.html to all the other pages”

You might also like