asw-v01: archive deferred content (packs, site, lab, legacy examples)
- 2.1: packs/ -> archive/packs/ - 2.2: site/ -> archive/site/ - 2.3: src/lab/ -> archive/lab/ - 2.4: examples/ -> archive/examples-legacy/ (SSI-based)
This commit is contained in:
parent
416fe2f180
commit
e47a9f4401
173 changed files with 11 additions and 5 deletions
82
archive/packs/flask/README.md
Normal file
82
archive/packs/flask/README.md
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
# ASW Flask/FastAPI Error Pack
|
||||
|
||||
Drop-in styled error responses for Flask and FastAPI applications.
|
||||
|
||||
## Usage
|
||||
|
||||
```python
|
||||
# Copy asw_errors.py to your project directory, then:
|
||||
|
||||
from flask import Flask
|
||||
from asw_errors import register_asw_errors
|
||||
|
||||
app = Flask(__name__)
|
||||
register_asw_errors(app)
|
||||
```
|
||||
|
||||
```python
|
||||
from fastapi import FastAPI
|
||||
from asw_errors import register_asw_errors
|
||||
|
||||
app = FastAPI()
|
||||
register_asw_errors(app)
|
||||
```
|
||||
|
||||
## What you get
|
||||
|
||||
ASW-styled HTML error pages for all HTTP error codes:
|
||||
|
||||
| Code | Status |
|
||||
|------|--------|
|
||||
| 400 | Bad Request |
|
||||
| 401 | Unauthorized |
|
||||
| 403 | Forbidden |
|
||||
| 404 | Not Found |
|
||||
| 405 | Method Not Allowed |
|
||||
| 408 | Request Timeout |
|
||||
| 409 | Conflict |
|
||||
| 410 | Gone |
|
||||
| 415 | Unsupported Media Type |
|
||||
| 422 | Unprocessable Entity |
|
||||
| 429 | Too Many Requests |
|
||||
| 500 | Internal Server Error |
|
||||
| 502 | Bad Gateway |
|
||||
| 503 | Service Unavailable |
|
||||
| 504 | Gateway Timeout |
|
||||
|
||||
For FastAPI, `RequestValidationError` (422) is also caught separately.
|
||||
|
||||
## Linking asw.css
|
||||
|
||||
By default, styles are inlined — no external dependencies needed. If your app already serves `asw.css`, link it instead:
|
||||
|
||||
```python
|
||||
register_asw_errors(app, css_url="/static/asw.css")
|
||||
```
|
||||
|
||||
The pages will then use your full theme including custom fonts.
|
||||
|
||||
## Custom app name
|
||||
|
||||
The nav bar shows your app's name. Override it:
|
||||
|
||||
```python
|
||||
register_asw_errors(app, app_name="My Service")
|
||||
```
|
||||
|
||||
Flask auto-detects from `app.name`; FastAPI from `app.title`. Both fall back to sensible defaults.
|
||||
|
||||
## Standalone HTML generation
|
||||
|
||||
The `error_html()` function is also exported if you need to generate pages directly:
|
||||
|
||||
```python
|
||||
from asw_errors import error_html
|
||||
|
||||
html = error_html(404, path="/missing/route")
|
||||
html = error_html(500, css_url="/static/asw.css", app_name="My API")
|
||||
```
|
||||
|
||||
## No dependencies at module level
|
||||
|
||||
Flask and FastAPI are imported lazily inside `register_asw_errors()` — so this file can live in a project that uses either framework without both installed.
|
||||
Loading…
Add table
Add a link
Reference in a new issue