Your goal is to implement the simplest web application. Use the following files from this repository as a base: https://github.com/GoIT-Python-Web/FullStack-Web-Development-hw3.
Based on the example in the manual, create a web application with routing for two HTML pages: index.html and message.html.
Additionally:
- Handle static resources during the application runtime:
style.css,logo.png. - Implement functionality for the form on the
message.htmlpage. - If a
404 Not Founderror occurs, return theerror.htmlpage. - Your application should run on port
3000.
The received byte string from the form should be converted into a dictionary and stored as a JSON file (data.json) in the storage directory.
The format for data.json should be 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"
}
}- The key for each message should be the timestamp when the message was received (
datetime.now()). - Each new message from the web application should be appended to the
storage/data.jsonfile with the timestamp.
- Add a
/readroute that generates an informational page. - This page should use a Jinja2 template to display all stored messages from the
data.jsonfile.
This additional task is not required to complete the homework assignment:
- Create a
Dockerfileand run your application as a Docker container. - Use the volumes mechanism to store data from
storage/data.jsonoutside the container.
Meeting these requirements is mandatory for evaluation by the mentor. If any requirement is not met, the mentor will return the homework for revision without evaluation.
If you need clarification or are stuck on a specific step, reach out to your mentor in Slack.
-
Routing:
- Two HTML pages are created:
index.htmlandmessage.html. - Static resources are handled (
style.cssandlogo.png). - The web application runs on port
3000.
- Two HTML pages are created:
-
Form Handling:
- The form on the
message.htmlpage works correctly and sends data (usernameandmessage). - 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" } }
- The form on the
-
Jinja2 Template:
- When accessing the
/readroute, a Jinja2 template page is returned, displaying all saved messages from thedata.jsonfile.
- When accessing the
-
404 Error Handling:
- A
404 Not Founderror returns theerror.htmlpage.
- A
-
Message Storage:
- Messages are stored in the
storage/data.jsonfile in JSON format, with the timestamp as the key.
- Messages are stored in the
- Create a
Dockerfileto run the application as a Docker container. - Use the volumes mechanism to store the
data.jsonfile outside the container.






