Created by Fabricio Braga
Last Updated: February 28, 2025
This is a simple Forum Application built with Flask, a Python micro-framework for web development. The application allows users to:
- Create Topics: Add new topics with a title, content, and author name.
- Reply to Topics: Add replies to existing topics.
- List Topics: View all topics along with their replies.
The application demonstrates key Flask concepts, including routing, request handling, templates, and error handling.
- Create a Topic: Add a new topic with a title, content, and author name.
- Reply to a Topic: Add replies to existing topics.
- List Topics: View all topics and their replies in a clean, minimalist design.
- Navigation Menu: Easily navigate between the home page and the "Create Topic" page.
- Flash Messages: Display success and error messages for user actions.
- Flask: A lightweight Python web framework.
- Jinja2: Templating engine for rendering HTML.
- CSS: Custom styles for a modern and minimalist design.
- Python: Backend logic and application development.
Before running the project, ensure you have the following installed:
- Download and install Python from https://www.python.org/.
- Verify the installation:
python3 --version
- Git is used for version control. You can download it from https://git-scm.com/.
Follow these steps to set up and run the project locally.
Clone the repository to your local machine:
git clone https://github.com/hackthegap/course-8-python-forum.git
cd course-8-python-forum
Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
Install the required dependencies:
pip install Flask
Start the Flask development server:
python3 run.py
The application will be available at http://localhost:5000
.
forum-app/
├── app/
│ ├── __init__.py # Flask application setup
│ ├── routes.py # Routes and request handling
│ ├── models.py # Data models (in-memory storage)
├── templates/
│ ├── base.html # Base template for all pages
│ ├── index.html # Home page (list of topics)
│ ├── topic.html # Topic details and replies
│ ├── create_topic.html # Form to create a new topic
│ ├── 404.html # Custom 404 error page
├── static/
│ ├── styles.css # Custom CSS styles
├── requirements.txt # List of dependencies
├── run.py # Entry point for the application
- Routes are defined in
app/routes.py
. - Key routes:
/
: Home page (lists all topics)./create_topic
: Form to create a new topic./topic/<int:topic_id>
: Displays a topic and its replies./topic/<int:topic_id>/reply
: Handles replies to a topic.
- Uses Jinja2 for templating.
- Templates are located in the
templates
folder. base.html
is the base template extended by other pages.
- Custom CSS styles are located in
static/styles.css
. - Linked in the
base.html
template using Flask’surl_for
function.
- Custom 404 error page (
templates/404.html
). - Flash messages for success and error notifications.
- Topics and replies are stored in an in-memory list (
app/models.py
).
- Displays a list of all topics.
- Click on a topic to view its details and replies.
- Click the "Create Topic" link in the navigation menu.
- Fill out the form and submit to create a new topic.
- Navigate to a topic’s detail page.
- Fill out the reply form and submit to add a reply.
- Use the navigation menu at the top of the page to switch between the home page and the "Create Topic" page.
The application includes unit tests for the ToDoList
class. Run the tests using the following command:
python3 -m unittest discover tests
To deploy the application in a production environment:
-
Install Gunicorn:
pip install gunicorn
-
Run the application with Gunicorn:
gunicorn run:app
-
Access the application at
http://localhost:8000
.
If you'd like to contribute to this project, follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourFeatureName
). - Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/YourFeatureName
). - Open a pull request.
- This project was created as part of a course to teach Flask and web development.
- Special thanks to the Flask and Python communities for providing excellent resources and tools.
If you have any questions or need further assistance, feel free to reach out to the instructor or open an issue in the repository.