Create a web application with routing for two HTML pages: index.html and message.html.
Additionally:
- Handle static resources such as
style.cssandlogo.png. - Implement functionality for working with a form on the
message.htmlpage. - In the event of a
404 Not Founderror, return anerror.htmlpage. - Your application should run on port
3000.
When working with the form, the received byte string should be converted into a dictionary and stored in a JSON file, data.json, located in the storage directory.
The format for storing the data.json file is as follows:
{
"2022-10-29 20:20:58.020261": {
"username": "krabaton",
"message": "First message"
},
"2022-10-29 20:21:11.812177": {
"username": "Krabat",
"message": "Second message"
}
}Each message's key should be the time the message was received datetime.now(), meaning every new message from the web application is appended to the storage/data.json file along with the time it was received.
Add a route, /read, which generates an informational page. This page should use a Jinja2 template and display all saved notifications from the data.json file.
- Create a
Dockerfileand run your application as a Docker container. - Use the
volumesmechanism to store thestorage/data.jsonfile outside the container.
1. Routing:
- Two HTML pages are created:
index.htmlandmessage.html. - Static resources (e.g.,
style.cssandlogo.png) are handled appropriately. - The web application runs on port 3000.
2. Form handling:
- The form on the
message.htmlpage works correctly and sends data (e.g., username and message). - Data from the form is converted into a dictionary and written to the
data.jsonfile in the following format:
{
"%timestamp%": {
"username": "example",
"message": "example message"
}
}3. The /read route:
- When accessed, it returns a Jinja2 template-based page displaying all stored messages from the
data.jsonfile.
4. Error handling:
- If a 404 error occurs, an
error.htmlpage is returned.
5. Message storage:
- Messages are stored in the
storage/data.jsonfile in JSON format, where the key is the message's receipt time.
6. Docker:
- A Dockerfile is created to run the application as a Docker container.
- The volumes mechanism is used to ensure the
data.jsonfile is stored outside the container.