def notification_redirect(request, ctx):
    if request.is_ajax():
        return JsonResponse(ctx)
    else:
        next_page = request.POST.get('next', reverse('notifications:all'))
        if not ctx['success']:
            return HttpResponseBadRequest(ctx['msg'])
        if is_safe_url(next_page):
            return HttpResponseRedirect(next_page)
        else:
            return HttpResponseRedirect(reverse('notifications:all'))
Helper to handle HTTP response after an action is performed on notification
dataset/ETHPy150Open v1k45/django-notify-x/notify/views.py/notification_redirect