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
def index(request):
return render(request,"employee/welcome.html")
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
POST Answer of Questions and ASK to Doubt