Flask web application inspired by the Flask Mega Tutorial.
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
- Python 3.12+ installed
- Basic familiarity with the terminal
- (Optional) Docker installed for containerization
git clone https://github.com/MicheleGrieco/microblog.git
cd microblogpython3 -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 shellpip install -r requirements.txtCreate 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
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
-
Set the
FLASK_APPenvironment variable:export FLASK_APP=microblog.py # macOS/Linux set FLASK_APP=microblog.py # Windows CMD $env:FLASK_APP = "microblog.py" # Windows PowerShell
-
(Optional) Initialize the database:
flask db init flask db migrate -m "Initial migration" flask db upgrade -
Start the development server:
flask run
-
Visit the app in your browser:
http://127.0.0.1:5000/
To run the unit tests:
python -m unittest tests.py
pytest tests.py # Alternative with pytest installedTo build and run the app in Docker:
docker build -t microblog .
docker run -p 5000:5000 microblog- 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
- No post editing or deletion functionality yet
- No deployment configuration for production
- Flask - Web framework
- Flask-SQLAlchemy - Database ORM
- Flask-Migrate - Database migrations
- Flask-Login - User session management
- Flask-WTF - Form handling
- Flask-Mail - Email support
- Flask-Moment - Datetime handling
- Flask-Babel - Internationalization
- PyJWT - JSON Web Tokens
- python-dotenv - Environment variables
- email-validator - Email validation
- langdetect - Language detection
- requests - HTTP client
- pytest - Testing framework
- mypy - Static type checking
- 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