Flask¶
The Flask adapter registers a context processor and exposes a for_entity
helper.
Prerequisites¶
- Python 3.10 or newer.
- Flask 2.3 or newer.
Install¶
Quick start¶
from flask import Flask
from easeo import SEOConfig
from easeo.adapters.flask import Easeo
app = Flask(__name__)
easeo = Easeo(
app,
SEOConfig(
canonical_host="example.com",
public_base_url="https://example.com",
)
)
API¶
| Member | Description |
|---|---|
Easeo(app, config) |
Construct and register on an app |
Easeo(config=config) |
Construct without an app |
easeo.init_app(app) |
Register on an app later. Raises ValueError without a config |
easeo.config |
The wrapped config, for use with build_seo_payload |
easeo.for_entity(entity, route) |
Build a payload and return it as a dict |
Templates¶
The adapter registers a seo_head(entity, route) helper:
The return value is Markup, so the | safe filter is optional.
Direct use¶
Deferred init¶
For application factories, construct without an app and initialize later:
Patterns¶
App factory and blueprints¶
See the factory example.
JSON API¶
for_entity returns a dict, so it serializes directly. See the
JSON example.
ETag responses¶
Return the payload's deterministic ETag and answer 304 when it matches. See
the ETag example.
Troubleshooting¶
| Symptom | Cause |
|---|---|
config must be provided before init_app |
Easeo() was created without a config |
| Helper missing in templates | init_app did not run, so the context processor is not registered |
| Head appears escaped | The helper returns Markup; avoid an extra | escape filter |
Notes¶
for_entityreturns a dict; the template helper returns HTML.- Entities need
entity_type,title, anddescription; a missingentity_typedefaults topage.