![]() |
The clock project aims to develop a simple yet functional clock application using modern web technologies. It combines the frontend capabilities of React.js for creating dynamic user interfaces with the styling power of Tailwind CSS for a sleek and responsive design. Additionally, the backend is built using Django, providing a robust framework for managing server-side logic and serving the frontend assets. Create a Clock using React and Tailwind using the Django FrameworkHere, is the step-by-step implementation of Clock using React, Tailwind, and Django Framework. Here, we will cover the article in 2 parts, frontend and then backend. To install Django in Python follow these steps. Backend Using DjangoTo start the project and app use this command django-admin startproject backend Now add this app to the ‘settings.py’ INSTALLED_APPS = [ For install the corsheaders run the below command pip install django-cors-headers File StructureSetting Necessary Filesapp/views.py: This Django view function, current_time, fetches the current time and formats it as a JSON response with the key “current_time”. It utilizes Django’s JsonResponse to return the time data in a JSON format.
backend/urls.py: This Django urlpatterns setup includes routes for both the admin interface
settings.py : In settings.py we added the crosheaders Middleware and also the some allowing host for integrating react.
Frontend Using React + TailwindTo start the project in react use this command npx create-react-app frontend Install the necessary library tailwindcss, react-dom and axios using the below command npm install tailwindcss File Structure : Creating User InterFaceApp.js: This React component fetches the current time from a Django backend every second using Axios. It then updates the state with the fetched time and displays it as a clock with hour, minute, and second hands rotating dynamically based on the current time.
index.js: Below, code renders the React application by mounting the `<App />` component into the HTML element with the id of ‘root’. It utilizes `React.StrictMode` for additional development mode checks.
tailwind.config.js: This is an empty Tailwind CSS configuration file, providing no additional content, theme extensions, or plugins.
App.css : This CSS code styles a clock component with hour, minute, and second hands. It positions them within a circular container and adjusts their sizes and positions accordingly. The hour and minute hands are black, while the second hand is red.
Deployement of the ProjectRun the server with the help of following command: python3 manage.py runserver Output |
Reffered: https://www.geeksforgeeks.org
Django |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |