Skip to content

Commit 716cfa3

Browse files
committed
Replace error.html with optional more specific category error templates (4xx.html)
1 parent 38a0a4a commit 716cfa3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

plain/plain/views/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,10 @@ For example:
258258
- `templates/404.html` - Page not found
259259
- `templates/403.html` - Forbidden
260260
- `templates/500.html` - Server error
261-
- `templates/error.html` - Generic fallback for all errors
261+
- `templates/4xx.html` - Generic fallback for all 4xx errors
262+
- `templates/5xx.html` - Generic fallback for all 5xx errors
263+
264+
Plain will first look for a specific status code template (e.g., `404.html`), then fall back to the category template (e.g., `4xx.html`). If neither exists, a plain HTTP response is returned.
262265

263266
The templates receive a context with `status_code` and `exception` variables.
264267

plain/plain/views/errors.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ def get_template_context(self) -> dict:
2929
return context
3030

3131
def get_template_names(self) -> list[str]:
32-
return [f"{self.status_code}.html", "error.html"]
32+
# Try specific status code first (e.g. "404.html")
33+
# Then fall back to category (e.g. "4xx.html" or "5xx.html")
34+
category = f"{str(self.status_code)[0]}xx"
35+
return [f"{self.status_code}.html", f"{category}.html"]
3336

3437
def get_request_handler(self) -> Callable[[], Any]:
3538
return self.get # All methods (post, patch, etc.) will use the get()

0 commit comments

Comments
 (0)