示例#1
0
def render_exception_to_response(request, exc, context=None):
    """
    Shortcut function to render a template with the exception nicely formatted.

    :param request: The request passed to the view.
    :param exc: The `Exception` or `ClientError`.
    :param context: Additional context as a `dict` to pass to the template.
    :return: A stringified response.
    """
    if context is None:
        context = {}

    error = None
    if type(exc) is ClientError:
        try:
            error = exc.args[0]
            error['invalid_params'] = error.get('invalid-params', None)
        except Exception:
            pass

    context.update({
        'view': {
            'title': _('Foutmelding'),
            'subtitle': _('Er ging iets mis...'),
        },
        'error': error,
        'exception': exc,
        'log_entries': Log.entries()
    })

    return render(request, 'demo/error.html', context)
示例#2
0
    def get_context_data(self, **kwargs):
        """
        Include log entries in the response.

        :param kwargs:
        :return:
        """
        context = super().get_context_data(**kwargs)

        context.update({
            'log_entries': Log.entries(),
        })

        return context