1.

How Do You Use Views In Django?

Answer»

Views will TAKE REQUEST to return response. Let’s write a view in Django : “example” using TEMPLATE example.html , using the date-time module to tell us exact time of reloading the page. Let’s edit a file called view.py, and it will be inside randomsite/randomapp/
To do this SAVE and copy following into a file:

from datatime import datetime
from django.shortcuts import render
def home (request):
return render(request, ‘Guru99_home.html’, {‘right_now’: datetime.utcnow()})
You have to determine the VIEW first, and then uncomment this line located in file urls.py
# url ( r ‘^$’ , ‘randomsite.randomapp.views.home’ , name ‘example’),
This will reload the site making changes obvious.

Views will take request to return response. Let’s write a view in Django : “example” using template example.html , using the date-time module to tell us exact time of reloading the page. Let’s edit a file called view.py, and it will be inside randomsite/randomapp/
To do this save and copy following into a file:

from datatime import datetime
from django.shortcuts import render
def home (request):
return render(request, ‘Guru99_home.html’, {‘right_now’: datetime.utcnow()})
You have to determine the VIEW first, and then uncomment this line located in file urls.py
# url ( r ‘^$’ , ‘randomsite.randomapp.views.home’ , name ‘example’),
This will reload the site making changes obvious.



Discussion

No Comment Found