0
# Blueprints
1
2
Blueprints allow you to organize your Flask application into modular components. They provide a way to group related views, templates, and static files.
3
4
## Capabilities
5
6
### Blueprint Class
7
8
```python { .api }
9
class Blueprint:
10
def __init__(
11
self,
12
name: str,
13
import_name: str,
14
static_folder: str | None = None,
15
static_url_path: str | None = None,
16
template_folder: str | None = None,
17
url_prefix: str | None = None,
18
subdomain: str | None = None,
19
url_defaults: dict | None = None,
20
root_path: str | None = None,
21
cli_group: str | None = None,
22
): ...
23
24
def route(self, rule: str, **options) -> Callable: ...
25
def before_request(self, f: Callable) -> Callable: ...
26
def after_request(self, f: Callable) -> Callable: ...
27
```
28
29
## Usage Examples
30
31
### Basic Blueprint
32
33
```python
34
from flask import Blueprint, render_template
35
36
# Create blueprint
37
auth_bp = Blueprint('auth', __name__, url_prefix='/auth')
38
39
@auth_bp.route('/login')
40
def login():
41
return render_template('auth/login.html')
42
43
@auth_bp.route('/logout')
44
def logout():
45
return 'Logged out'
46
47
# Register with app
48
app.register_blueprint(auth_bp)
49
```