Create a layout.html with a suitable header and footer. Inherit this layout.html and create 3 additional pages: contact us, About Us, and Home page
Program:-
views.py:-
from datetime import date from django.http import HttpResponse from django.shortcuts import render from django.template import Context, Template def home(request): return render(request, 'home.html') def aboutus(request): return render(request, 'aboutus.html') def contactus(request): return render(request, 'contactus.html')
urls.py:-
from django.urls import path, re_path from ap2.views import aboutus, home, contactus urlpatterns = [ path('aboutus/', aboutus), path('home/', home), path('contactus/', contactus), ]
templates/layout.html:-
<!-- layout.html --> <html> <title>{% block title %}{% endblock %}</title> <style type="text/css"> nav {background-color: lightblue; padding: 10px;} </style> <body> <nav> <a href="/home/">Home</a> | <a href="/aboutus/">About Us</a> | <a href="/contactus/">Contact Us</a> | </nav> <section> {% block content %}{% endblock %} </section> <footer> <hr> © AIML, Developed by ABC, Inc. </footer> </body> </html>
templates/aboutus.html:-
<!-- aboutus.html --> {% extends 'layout.html' %} {% block title %} About Us {% endblock %} {% block content %} <h2>We are Django developers</h2> {% endblock %}
templates/home.html:-
<!-- home.html --> {% extends 'layout.html' %} {% block title %} Home {% endblock %} {% block content %} <h2>This is the home page</h2> {% endblock %}
templates/contactus.html:-
<!-- contactus.html --> {% extends 'layout.html' %} {% block title %} Contact Us {% endblock %} {% block content %} <h2>Our phone: 1234567890 <br> Address: vtu updates</h2> {% endblock %}