Define Views
Views handle the logic for processing requests and generating responses in an application.
In the app’s directory (homepage), open the views.py file. Add the following:
from django.shortcuts import render
from datetime import datetime
def home(request):
today = datetime.now().date()
return render(request, “homepage/home.html”, {“today” : today})
Here, in the code above, the home function takes an object representing the incoming HTTP request. The render function takes the HTTP request, the template, and the data to be passed to the template (in this case, the ‘today’ variable with the current date).
The render function then processes the template, and replaces any placeholders with the provided data. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access