1fromplain.httpimportResponseBase 2fromplain.templatesimportTemplateFileMissing 3 4from.templatesimportTemplateView 5 6 7classErrorView(TemplateView): 8status_code:int 910def__init__(self,*,status_code=None,exception=None)->None:11# Allow creating an ErrorView with a status code12# e.g. ErrorView.as_view(status_code=404)13self.status_code=status_codeorself.status_code1415# Allow creating an ErrorView with an exception16self.exception=exception1718defget_template_context(self):19context=super().get_template_context()20context["status_code"]=self.status_code21context["exception"]=self.exception22returncontext2324defget_template_names(self)->list[str]:25return[f"{self.status_code}.html","error.html"]2627defget_request_handler(self):28returnself.get# All methods (post, patch, etc.) will use the get()2930defget_response(self)->ResponseBase:31response=super().get_response()32# Set the status code we want33response.status_code=self.status_code34returnresponse3536defget(self):37try:38returnsuper().get()39exceptTemplateFileMissing:40returnself.status_code