Show Time Django Simple Coding Notes
Show Time Django Simple Coding Notes
Description: Create a web page that displays the current date and time.
Key Concepts:
• URL routing
• Views
• Templates
• Python’s datetime module
Features:
import datetime
def current_time(request):
urlpatterns = [
Include the app’s URLs in the project’s main URL con guration.
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('timeapp.urls')), # Include timeapp
URLs
]
Create the HTML template that displays the current time. Optionally, use JavaScript to update the
time dynamically.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Current Time</title>
</head>
<body>
</div>
</body>
</html>
Once everything is set up, you can run the Django server:
Visit http://127.0.0.1:8000/time/ in your browser to see the current date and time
displayed, styled with Bootstrap.
fl