def twilio_view(f):
@csrf_exempt<EOL>@wraps(f)<EOL>def decorator(request, *args, **kwargs):<EOL><INDENT>if request.method != "<STR_LIT:POST>":<EOL><INDENT>logger.error("<STR_LIT>", extra={"<STR_LIT>": request})<EOL>return HttpResponseNotAllowed(request.method)<EOL><DEDENT>if not getattr(settings, "<STR_LIT>"):<EOL><INDENT>try:<EOL><INDENT>validator = RequestValidator(settings.TWILIO_AUTH_TOKEN)<EOL>url = request.build_absolute_uri()<EOL>if "<STR_LIT>" in request.META:<EOL><INDENT>protocol = "<STR_LIT>" if request.META["<STR_LIT>"] == "<STR_LIT>" else "<STR_LIT:http>"<EOL>url = "<STR_LIT>".format(<EOL>protocol, request.META["<STR_LIT>"], request.META["<STR_LIT>"]<EOL>)<EOL><DEDENT>signature = request.META["<STR_LIT>"]<EOL><DEDENT>except (AttributeError, KeyError) as e:<EOL><INDENT>logger.exception("<STR_LIT>", extra={"<STR_LIT>": request})<EOL>return HttpResponseForbidden("<STR_LIT>" % e)<EOL><DEDENT>if not validator.validate(url, request.POST, signature):<EOL><INDENT>logger.error(<EOL>"<STR_LIT>",<EOL>url, request.POST, signature, extra={"<STR_LIT>": request}<EOL>)<EOL>return HttpResponseForbidden("<STR_LIT>")<EOL><DEDENT><DEDENT>response = f(request, *args, **kwargs)<EOL>if isinstance(response, six.text_type):<EOL><INDENT>return HttpResponse(response, mimetype="<STR_LIT>")<EOL><DEDENT>elif isinstance(response, Verb):<EOL><INDENT>return HttpResponse(force_text(response), mimetype="<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>return response<EOL><DEDENT><DEDENT>return decorator<EOL>
This decorator provides several helpful shortcuts for writing Twilio
    views.

        - It ensures that only requests from Twilio are passed through. This
          helps protect you from forged requests.

        - It ensures your view is exempt from CSRF checks via Django's
          @csrf_exempt decorator. This is necessary for any view that accepts
          POST requests from outside the local domain (eg: Twilio's servers).

        - It allows your view to (optionally) return TwiML to pass back to
          Twilio's servers instead of building a ``HttpResponse`` object
          manually.

        - It allows your view to (optionally) return any ``twilio.Verb`` object
          instead of building a ``HttpResponse`` object manually.

    Usage::

        from twilio.twiml import Response

        @twilio_view
        def my_view(request):
            r = Response()
            r.sms("Thanks for the SMS message!")
            return r