2010-01-11 01:35:01 +08:00
|
|
|
from django import http
|
2010-10-30 15:19:04 +08:00
|
|
|
from django.core.exceptions import PermissionDenied
|
2015-01-10 05:59:00 +08:00
|
|
|
from django.template import engines
|
2010-12-07 21:57:01 +08:00
|
|
|
from django.template.response import TemplateResponse
|
|
|
|
|
2010-01-11 01:35:01 +08:00
|
|
|
|
2010-10-30 15:19:04 +08:00
|
|
|
def normal_view(request):
|
|
|
|
return http.HttpResponse('OK')
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2010-12-07 21:57:01 +08:00
|
|
|
def template_response(request):
|
2016-07-19 16:45:32 +08: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 21:57:01 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2010-12-07 21:57:01 +08:00
|
|
|
def template_response_error(request):
|
2015-01-10 05:59:00 +08:00
|
|
|
template = engines['django'].from_string('{%')
|
|
|
|
return TemplateResponse(request, template)
|
2010-12-07 21:57:01 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2010-10-30 15:19:04 +08:00
|
|
|
def not_found(request):
|
|
|
|
raise http.Http404()
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2010-10-30 15:19:04 +08:00
|
|
|
def server_error(request):
|
|
|
|
raise Exception('Error in view')
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2010-10-30 15:19:04 +08:00
|
|
|
def null_view(request):
|
|
|
|
return None
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2010-10-30 15:19:04 +08:00
|
|
|
def permission_denied(request):
|
|
|
|
raise PermissionDenied()
|
2015-06-05 21:30:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
def exception_in_render(request):
|
|
|
|
class CustomHttpResponse(http.HttpResponse):
|
|
|
|
def render(self):
|
|
|
|
raise Exception('Exception in HttpResponse.render()')
|
|
|
|
|
|
|
|
return CustomHttpResponse('Error')
|