Speed up development with full-stack environments for every branch.

Learn More

Rendering a template from Django views [Python and templates]

1004 Runs 9087 Views 2613 Copies


lgp171188 18

published 3 years ago

# Import the datetime module so that we can get the current time
import datetime

# Import the render shortcut so that we can use it to render templates
# in the response
from django.shortcuts import render

# This view method handles the request for the root URL /
# See urls.py for the mapping.
def index(request):
    # Render the index.html template with a context dictionary
    # that has a key called 'time' with current time obtained from
    # the datetime module as the value.
    return render(request, "index.html", {'time' : datetime.datetime.now()})
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).