How to create multiple views.py in Django application

0

You know very well when we create an application in Django then we can not write complete code on views.py because if a line of code will be exceeded then the application load time will be increased.


We can create multiple views.py to refactor the code on multiple files that will be better for the understandability of code and reduce file load.

.........................................................................................................................................................


Step to create another views.py


1) go into the app and create one python file, I provided the name myviews.py

    and write the following code


from django.shortcuts import render


def welcome(request):

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


2)  create .HTML file under templates directory

     <!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

<h1>Welcome fhdgfhdgf hdgfhjdg fhgdf</h1>

</body>

</html>


3)  create urls.py and define URL


from django.urls import path

from . import myview

urlpatterns=[

path('welcome',myview.welcome,name='welcome')

]












Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)