An open API service indexing awesome lists of open source software.

https://github.com/ianolpx/learn-tornado

A collection of example projects for learning the Python Tornado web framework.
https://github.com/ianolpx/learn-tornado

examples learning python-tornado tornado

Last synced: 6 months ago
JSON representation

A collection of example projects for learning the Python Tornado web framework.

Awesome Lists containing this project

README

          

# Learn Tornado

A collection of example projects for learning the Python Tornado web framework.

## Project Structure

### 01-basics/ - Basic Concepts
- **hello-world/**: Basic Tornado Hello World example
- **templates/**: Template basic usage (variables, functions)
- **templates-inheritance/**: Template inheritance and link processing

### 02-ui/ - User Interface
- **semantic-ui-basic/**: Basic Semantic UI components
- **forms/**: Semantic UI form components
- **file-upload/**: File upload functionality

### 03-authentication/ - Authentication System
- **basic-login/**: Basic login system
- **login-register/**: Login + registration system

### 04-database/ - Database Integration
- **sqlite-integration/**: SQLite3 database integration

### 05-advanced/ - Advanced Features
- **websocket/**: WebSocket real-time communication
- **ajax-examples/**: AJAX examples
- **checkid/**: ID duplicate check
- **charts/**: Chart libraries (Circliful, Highcharts)
- **interval/**: Periodic updates
- **timeout/**: Timeout handling
- **async-processing/**: Asynchronous processing (MongoDB integration)
- **crypto/**: CryptoJS encryption

## Code Quality Improvements

All examples have been refactored with the following improvements:

### 🏗️ **Modern Python Structure**
- Python 3.6+ syntax and features
- Type hints and docstrings
- Proper error handling and logging
- Clean code organization

### 📚 **Enhanced Documentation**
- Comprehensive docstrings for all classes and methods
- Clear code comments explaining functionality
- Consistent naming conventions
- English documentation throughout

### 🔧 **Better Configuration**
- Command-line argument parsing with `tornado.options`
- Environment-based configuration
- Debug mode support
- Flexible port configuration

### 🛡️ **Improved Security**
- Secure cookie handling
- XSRF protection
- Input validation and sanitization
- Error handling without information leakage

### 🚀 **Performance Optimizations**
- Asynchronous operations where appropriate
- Efficient database queries
- Proper connection management
- Resource cleanup

## How to Run

### Prerequisites
```bash
# Install Python 3.6+ and pip
# Then install dependencies
pip install -r requirements.txt
```

### Running Examples
Each project directory contains a complete, runnable example:

```bash
# Navigate to any example directory
cd 01-basics/hello-world

# Run the application
python app.py

# Or with custom port
python app.py --port=8080
```

The default port is 3000. Access `http://localhost:3000` in your browser.

## Learning Path

1. **01-basics/hello-world** - Understand basic Tornado concepts
2. **01-basics/templates** - Learn template system
3. **01-basics/templates-inheritance** - Learn template inheritance
4. **02-ui/semantic-ui-basic** - Learn UI framework usage
5. **02-ui/forms** - Learn form handling
6. **02-ui/file-upload** - Implement file upload
7. **03-authentication/basic-login** - Basic authentication system
8. **03-authentication/login-register** - User management system
9. **04-database/sqlite-integration** - Database integration
10. **05-advanced/websocket** - Real-time communication
11. **05-advanced/ajax-examples** - AJAX utilization
12. **05-advanced/async-processing** - Asynchronous processing
13. **05-advanced/crypto** - Encryption handling

## Requirements

- Python 3.6+
- Tornado 6.1+
- SQLite3 (included by default)
- MongoDB (for async-processing example)
- Motor (MongoDB async driver)

## Installation

```bash
# Clone the repository
git clone
cd learn-tornado

# Install dependencies
pip install -r requirements.txt
```

## Development

### Code Style
All code follows PEP 8 guidelines with:
- Consistent indentation (4 spaces)
- Descriptive variable names
- Proper import organization
- Comprehensive error handling

### Testing
```bash
# Run tests (if pytest is installed)
pytest

# Code formatting (if black is installed)
black .

# Linting (if flake8 is installed)
flake8 .
```

## License

MIT License