0
0
Flaskframework~30 mins

Room-based messaging in Flask - Mini Project: Build & Apply

Choose your learning style9 modes available
Room-based messaging
📖 Scenario: You are building a simple chat application where users can join different chat rooms and send messages visible only to that room.
🎯 Goal: Create a Flask app that supports multiple chat rooms. Users can join a room and send messages that only appear in that room.
📋 What You'll Learn
Create a dictionary to hold chat rooms and their messages
Add a variable to track the current room
Write a function to add messages to the current room
Complete the Flask route to display messages for the current room
💡 Why This Matters
🌍 Real World
Chat apps often separate conversations into rooms or channels so users can join topics they like.
💼 Career
Understanding how to manage data for different user groups and display dynamic content is key for web developers.
Progress0 / 4 steps
1
Create the chat rooms data structure
Create a dictionary called chat_rooms with these exact keys and values: 'general': [], 'sports': [], 'music': [].
Flask
Need a hint?

Use curly braces to create a dictionary. Each key is a room name and the value is an empty list for messages.

2
Add current room variable
Add a variable called current_room and set it to the string 'general'.
Flask
Need a hint?

Just assign the string 'general' to the variable current_room.

3
Write function to add messages
Write a function called add_message that takes a parameter message and appends it to the list in chat_rooms[current_room].
Flask
Need a hint?

Use the append() method on the list for the current room.

4
Complete Flask route to show messages
Complete the Flask route function called show_room that returns a string joining all messages in chat_rooms[current_room] separated by commas.
Flask
Need a hint?

Use the join() method on the list of messages for the current room.