Create a Flask-based web application with a frontend that features two interactive buttons. When a button is clicked, an event is sent to the backend, which randomly responds with either "success" or "failure". This response, along with the button clicked, should be logged in a UI element on the frontend (a "log viewer"). Importantly, this log should persist between user sessions. Use any modern CSS and JavaScript framework (like React, Vue.js, Angular or other) to enhance interactivity.
git clone https://github.com/nicolaefilat/LogViewer.git
cd react-frontend
npm install
to install dependenciesvite dev
to run the dev server and navigate to the url from the terminal
The frontend should look like this:
It is also responsive for mobile devices too.
pip install -r requirements.txt
flask run
- If
Button 1
is clicked a log item will appear with the nameButton 1
and a random status - If
Button 2
is clicked a log item will appear with the nameButton 2
and a random status - If
Reset
is clicked the localStorage is cleared and the page is refreshed resulting in an empty log. - If
Refresh
is clicked the page is refreshed to show that the log is persisted
The main idea is that the server generates a session_id
for the user when the user first visits the page and using that session_id
the server stores the logs on the server in memory (real uses cases would use a database).
The session_id
is stored in the browser's localStorage to enable reopening the same log even after closing the browser.
The general architecture is shown below
If the initial setup does not work click reset
and restart the server. This should make sure that the client requests a new session from the server.