Coverage for /Users/davegaeddert/Developer/dropseed/plain/plain/plain/views/errors.py: 48%
21 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-23 11:16 -0600
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-23 11:16 -0600
1from plain.http import ResponseBase
2from plain.templates import TemplateFileMissing
4from .templates import TemplateView
7class ErrorView(TemplateView):
8 status_code: int
10 def __init__(self, status_code=None) -> None:
11 # Allow creating an ErrorView with a status code
12 # e.g. ErrorView.as_view(status_code=404)
13 if status_code is not None:
14 self.status_code = status_code
16 def get_template_names(self) -> list[str]:
17 return [f"{self.status_code}.html", "error.html"]
19 def get_request_handler(self):
20 return self.get # All methods (post, patch, etc.) will use the get()
22 def get_response(self) -> ResponseBase:
23 response = super().get_response()
24 # Set the status code we want
25 response.status_code = self.status_code
26 return response
28 def get(self):
29 try:
30 return super().get()
31 except TemplateFileMissing:
32 return self.status_code