What is Templates in Django Framework?



Template is used to create a design layer in the Django application, we can create code of HTML under the templates directory.

How to manage template under Django application.

1)  Create Project, Create APP, Create APP Url

2)  Create templates directory(folder) under app then again create directory under templates with appname.

3)  Create Html file under templates/appname

4) Load HTML files using render()

  def  methodname(request):

      return render(request, "appname/htmlfilename")

Now I am implementing Live Example of Templates:-

1)  create app

2)  add app info (appname on settings.py and create URL under urls.py)

3) create app urls.py and declare URL for index method of views.py

from django.urls import path

from . import views




4)  Create Method under Views.py

from django.shortcuts import render

def index(request):


5)  create templates directory under app and appname subdirectory under templates then create HTML file to design layout.

<!DOCTYPE html>


<h1>Latest Python Interview Session</h1>

 <iframe width="860" height="515" src="https://www.youtube.com/embed/3ohsUzzmLyE" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

5) load templates file using render

def index(request):

     return render(request,"employee/welcome.html")


Post a Comment


POST Answer of Questions and ASK to Doubt

Post a Comment (0)