def captcha_refresh(request):
    if not request.is_ajax():
        raise Http404

    new_key = CaptchaStore.generate_key()
    to_json_response = {
        'key': new_key,
        'image_url': captcha_image_url(new_key),
    }
    return HttpResponse(json.dumps(to_json_response), content_type='application/json')
Return json with new captcha for ajax refresh request
dataset/ETHPy150Open mbi/django-simple-captcha/captcha/views.py/captcha_refresh