Skip to content
MicheleGriecoPublic

About

A Flask web app for user authentication and microblogging, inspired by the Flask Mega Tutorial. Features registration, login, session management, and a relational database for users and posts.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Microblog

Flask web application inspired by the Flask Mega Tutorial.

Overview

This web application demonstrates:

  • User authentication (login/logout), registration, and password reset via email
  • User profile pages with Gravatar avatars, "about me" field, and last seen time
  • Edit user profile (username and "about me" field)
  • Create, display, and paginate posts (persisted in the database)
  • Follow and unfollow other users
  • Explore page to view all posts from all users
  • Flash messages and form validation
  • Error handling with custom 404 and 500 pages
  • Internationalization (English, Spanish, Italian) with Flask-Babel
  • Post language detection and translation (Microsoft Translator API)
  • Responsive UI with Bootstrap and Moment.js for timestamps
  • Docker support for containerized deployment
  • Unit tests for models

Prerequisites

  • Python 3.12+ installed
  • Basic familiarity with the terminal
  • (Optional) Docker installed for containerization

Getting Started

1. Clone the repository

git clone https://github.com/MicheleGrieco/microblog.git
cd microblog

2. Create and activate a virtual environment

python3 -m venv venv
source venv/bin/activate       # On macOS/Linux
venv\Scripts\activate          # On Windows (cmd.exe)
venv\Scripts\Activate.ps1      # On Windows PowerShell
# Use only the command appropriate for your shell

3. Install dependencies

pip install -r requirements.txt

4. Set environment variables (optional, for email and translation)

Create a .env file or set variables in shell:

SECRET_KEY=your-secret-key
MAIL_SERVER=smtp.example.com
MAIL_PORT=587
MAIL_USE_TLS=1
MAIL_USERNAME=your-email@example.com
MAIL_PASSWORD=your-email-password
MS_TRANSLATOR_KEY=your-microsoft-translator-key

Project Structure

microblog/
├── app/
│   ├── __init__.py            # Flask app initialization
│   ├── cli.py                 # Custom Flask CLI commands
│   ├── email.py               # Email functionality
│   ├── models.py              # Database models
│   ├── translate.py           # Translation service
│   ├── auth/                  # Authentication blueprint
│   │   ├── __init__.py
│   │   ├── email.py          # Password reset emails
│   │   ├── forms.py          # Login/registration forms
│   │   └── routes.py         # Auth routes
│   ├── errors/               # Error handling blueprint
│   │   ├── __init__.py
│   │   └── handlers.py       # Error handlers
│   ├── main/                 # Main application blueprint
│   │   ├── __init__.py
│   │   ├── forms.py         # Post and profile forms
│   │   └── routes.py        # Main routes
│   ├── static/
│   │   └── loading.gif      # Loading animation
│   ├── templates/
│   │   ├── _post.html        # Post template
│   │   ├── base.html         # Base template
│   │   ├── bootstrap_wtf.html
│   │   ├── edit_profile.html
│   │   ├── index.html        # Homepage
│   │   ├── user.html         # User profile
│   │   ├── auth/
│   │   │   ├── login.html
│   │   │   ├── register.html
│   │   │   └── reset_password.html
│   │   ├── email/
│   │   │   └── reset_password.html
│   │   └── errors/
│   │       ├── 404.html
│   │       └── 500.html
│   └── translations/          # i18n translations
│       ├── es/
│       └── it/
├── migrations/
├── app.db                     # SQLite database file
├── config.py                  # App configuration
├── Dockerfile                 # Docker support
├── microblog.py               # WSGI entry point
├── requirements.txt           # Python dependencies
├── tests.py                   # Unit tests for models
└── README.md                  # Project documentation

Running the App

  1. Set the FLASK_APP environment variable:

    export FLASK_APP=microblog.py       # macOS/Linux
    set FLASK_APP=microblog.py          # Windows CMD
    $env:FLASK_APP = "microblog.py"     # Windows PowerShell
  2. (Optional) Initialize the database:

    flask db init
    flask db migrate -m "Initial migration"
    flask db upgrade
  3. Start the development server:

    flask run
  4. Visit the app in your browser:

    http://127.0.0.1:5000/
    

Running Tests

To run the unit tests:

python -m unittest tests.py
pytest tests.py # Alternative with pytest installed

Docker Support

To build and run the app in Docker:

docker build -t microblog .
docker run -p 5000:5000 microblog

Current Features

  • User authentication (login/logout) with email/password
  • User registration with email validation
  • Password reset via email
  • User profiles with:
    • Gravatar avatars
    • "About me" section
    • Last seen time tracking
    • Follow/unfollow functionality
  • Posts system with:
    • Creation and display
    • Pagination (25 posts per page)
    • Language detection
    • Translation support via Microsoft Translator API
  • Multilanguage support (English, Spanish, Italian)
  • Error handling with custom 404 and 500 pages
  • Modular application structure with blueprints:
    • auth: User authentication
    • main: Core functionality
    • errors: Error handling
  • Flask shell context for testing
  • Unit tests for User model
  • SQLite database with migrations
  • Bootstrap-based responsive UI

Limitations

  • No post editing or deletion functionality yet
  • No deployment configuration for production

Main Dependencies


Next Steps

  • Add post editing and deletion
  • Add post search functionality
  • Add custom avatar upload
  • Add user notifications
  • Add API endpoints
  • Add CSRF protection
  • Add rate limiting
  • Configure production deployment
  • Add continuous integration/deployment
  • Improve test coverage

Useful Links

About

A Flask web app for user authentication and microblogging, inspired by the Flask Mega Tutorial. Features registration, login, session management, and a relational database for users and posts.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages