Develop a Django app that displays current date and time in server

Develop a Django app that displays current date and time in server

Program:-

views.py:-

from django.shortcuts import render
from django.http import HttpResponse
import datetime

# Create your views here.
def current_datetime(request):
    now = datetime.datetime.now()
    html = "<html><body><h1>It is now %s.</h1></body></html>" % now
    return HttpResponse(html)

urls.py:-

# In project named first, make following changes to urls.py
from django.contrib import admin
from django.urls import path
from lab11.views import current_datetime

urlpatterns = [
    path('cdt/', current_datetime),
]

Leave a Reply

Your email address will not be published. Required fields are marked *