Module2 FSD
Module2 FSD
django templates
views.py
def greet(request,user):
#uname=user
d={'user':user}
return render(request,'greet.html',d)
urls.py
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
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
<!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
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
{% 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>
© Designed and Developed by Dr. Harish Kumar B T, CSE, BIT, Bangalore-04
</footer>
</body>
</html>