from django.http import HttpResponse, HttpResponseBadRequest
from django.views.decorators.http import require_POST
import json

def hello(request):
    return HttpResponse("Hello, world.  Badges!!!")

@require_POST
def badge_issued_hook(request):
    try:
        data = json.loads(request.body)
    except ValueError:
        return HttpResponseBadRequest("Bad JSON")

    return HttpResponse("Hello, world.  Badges!!!")

from django.http import HttpResponse, HttpResponseBadRequest
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
import json

def hello(request):
    return HttpResponse("Hello, world.  Badges!!!")

@require_POST
@csrf_exempt
def badge_issued_hook(request):
    try:
        data = json.loads(request.body)
    except ValueError:
        return HttpResponseBadRequest("Bad JSON")

    return HttpResponse("Hello, world.  Badges!!!")

Make webhook exempt from CSRF protection
Make webhook exempt from CSRF protection

Soon, we will add JWT verification, to replace it.

  from django.http import HttpResponse, HttpResponseBadRequest
+ from django.views.decorators.csrf import csrf_exempt
  from django.views.decorators.http import require_POST
  import json
  
  def hello(request):
      return HttpResponse("Hello, world.  Badges!!!")
  
  @require_POST
+ @csrf_exempt
  def badge_issued_hook(request):
      try:
          data = json.loads(request.body)
      except ValueError:
          return HttpResponseBadRequest("Bad JSON")
  
      return HttpResponse("Hello, world.  Badges!!!")
  
Make webhook exempt from CSRF protection
## Code Before:
from django.http import HttpResponse, HttpResponseBadRequest
from django.views.decorators.http import require_POST
import json

def hello(request):
    return HttpResponse("Hello, world.  Badges!!!")

@require_POST
def badge_issued_hook(request):
    try:
        data = json.loads(request.body)
    except ValueError:
        return HttpResponseBadRequest("Bad JSON")

    return HttpResponse("Hello, world.  Badges!!!")

## Instruction:
Make webhook exempt from CSRF protection
## Code After:
from django.http import HttpResponse, HttpResponseBadRequest
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
import json

def hello(request):
    return HttpResponse("Hello, world.  Badges!!!")

@require_POST
@csrf_exempt
def badge_issued_hook(request):
    try:
        data = json.loads(request.body)
    except ValueError:
        return HttpResponseBadRequest("Bad JSON")

    return HttpResponse("Hello, world.  Badges!!!")
