Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

 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


urlpatterns=[

path("",views.index,name='index'),



]



4)  Create Method under Views.py


from django.shortcuts import render



def index(request):

pass



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

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

</head>
<body>

<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>
</body>
</html>





5) load templates file using render
        

def index(request):

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




,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,












Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post