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

Learn More

Simple AJAX Request to get server time using Django [Python]

973 Runs 3454 Views 626 Copies
Saved

Saved

bhawani0915 49

bhawani0915
published 4 years ago

from django.http import HttpResponse
from django.template import loader
from django.template import RequestContext
import datetime


# Create your views here.
def home(request):
    context = {}
    template = loader.get_template('home.html')
    data = RequestContext(request, context)
    return HttpResponse(template.render(data))
    

# to get server time
def ajax_call(request):
    now = datetime.datetime.now()
    return HttpResponse(now)
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).