2010-10-30 07:19:04 +00:00
|
|
|
from django.core.exceptions import PermissionDenied
|
2018-11-21 22:41:23 +00:00
|
|
|
from django.http import HttpResponse
|
2015-01-09 21:59:00 +00:00
|
|
|
from django.template import engines
|
2010-12-07 13:57:01 +00:00
|
|
|
from django.template.response import TemplateResponse
|
|
|
|
|
2010-01-10 17:35:01 +00:00
|
|
|
|
2010-10-30 07:19:04 +00:00
|
|
|
def normal_view(request):
|
2017-02-25 06:48:20 +00:00
|
|
|
return HttpResponse("OK")
|
2010-10-30 07:19:04 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-12-07 13:57:01 +00:00
|
|
|
def template_response(request):
|
2016-07-19 08:45:32 +00:00
|
|
|
template = engines["django"].from_string(
|
|
|
|
"template_response OK{% for m in mw %}\n{{ m }}{% endfor %}"
|
|
|
|
)
|
|
|
|
return TemplateResponse(request, template, context={"mw": []})
|
2010-12-07 13:57:01 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-10-30 07:19:04 +00:00
|
|
|
def server_error(request):
|
|
|
|
raise Exception("Error in view")
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-10-30 07:19:04 +00:00
|
|
|
def permission_denied(request):
|
|
|
|
raise PermissionDenied()
|
2015-06-05 13:30:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def exception_in_render(request):
|
2017-02-25 06:48:20 +00:00
|
|
|
class CustomHttpResponse(HttpResponse):
|
2015-06-05 13:30:03 +00:00
|
|
|
def render(self):
|
|
|
|
raise Exception("Exception in HttpResponse.render()")
|
|
|
|
|
|
|
|
return CustomHttpResponse("Error")
|
2020-02-12 22:15:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_exception_in_render(request):
|
|
|
|
class CustomHttpResponse(HttpResponse):
|
|
|
|
async def render(self):
|
|
|
|
raise Exception("Exception in HttpResponse.render()")
|
|
|
|
|
|
|
|
return CustomHttpResponse("Error")
|