from django.http import JsonResponse, HttpResponse, HttpResponseBadRequest
from django.views.decorators.csrf import csrf_exempt
import json
from helpers import get_school_list, check_signup_email


def get_schools(request):
    resp = JsonResponse({'schools': get_school_list()})
    resp['Access-Control-Allow-Origin'] = 'http://localhost:3000'
    return resp


@csrf_exempt
def signup(request):
    if request.method == "POST":
        signup_parameters = json.loads(request.body.decode('utf-8'))
        if check_signup_email(signup_parameters['email']):
            resp = HttpResponse('Signup OK')
        else:
            resp = HttpResponseBadRequest('Invalid univesity email')
    elif request.method == "OPTIONS":
        resp = HttpResponse('')
        resp['Access-Control-Allow-Headers'] = 'Content-Type'
    else:
        resp = HttpResponseBadRequest('')
    resp['Access-Control-Allow-Origin'] = 'http://localhost:3000'
    return resp

from django.http import JsonResponse, HttpResponse, HttpResponseBadRequest
from django.views.decorators.csrf import csrf_exempt
import json
from helpers import get_school_list, check_signup_email


def get_schools(request):
    resp = JsonResponse({'schools': get_school_list()})
    resp['Access-Control-Allow-Origin'] = 'http://localhost:3000'
    return resp


@csrf_exempt
def signup(request):
    if request.method == "POST":
        signup_parameters = json.loads(request.body.decode('utf-8'))
        if check_signup_email(signup_parameters['email']):
            resp = HttpResponse('Signup OK')
        else:
            resp = HttpResponseBadRequest('Invalid univesity email')
    elif request.method == "OPTIONS":
        resp = HttpResponse('')
        resp['Access-Control-Allow-Headers'] = 'Content-Type'
    else:
        resp = HttpResponseBadRequest('Invalid request method')
    resp['Access-Control-Allow-Origin'] = 'http://localhost:3000'
    return resp

Add error message to BadRequest signup response for invalid method
Add error message to BadRequest signup response for invalid method

  from django.http import JsonResponse, HttpResponse, HttpResponseBadRequest
  from django.views.decorators.csrf import csrf_exempt
  import json
  from helpers import get_school_list, check_signup_email
  
  
  def get_schools(request):
      resp = JsonResponse({'schools': get_school_list()})
      resp['Access-Control-Allow-Origin'] = 'http://localhost:3000'
      return resp
  
  
  @csrf_exempt
  def signup(request):
      if request.method == "POST":
          signup_parameters = json.loads(request.body.decode('utf-8'))
          if check_signup_email(signup_parameters['email']):
              resp = HttpResponse('Signup OK')
          else:
              resp = HttpResponseBadRequest('Invalid univesity email')
      elif request.method == "OPTIONS":
          resp = HttpResponse('')
          resp['Access-Control-Allow-Headers'] = 'Content-Type'
      else:
-         resp = HttpResponseBadRequest('')
+         resp = HttpResponseBadRequest('Invalid request method')
      resp['Access-Control-Allow-Origin'] = 'http://localhost:3000'
      return resp
  
Add error message to BadRequest signup response for invalid method
## Code Before:
from django.http import JsonResponse, HttpResponse, HttpResponseBadRequest
from django.views.decorators.csrf import csrf_exempt
import json
from helpers import get_school_list, check_signup_email


def get_schools(request):
    resp = JsonResponse({'schools': get_school_list()})
    resp['Access-Control-Allow-Origin'] = 'http://localhost:3000'
    return resp


@csrf_exempt
def signup(request):
    if request.method == "POST":
        signup_parameters = json.loads(request.body.decode('utf-8'))
        if check_signup_email(signup_parameters['email']):
            resp = HttpResponse('Signup OK')
        else:
            resp = HttpResponseBadRequest('Invalid univesity email')
    elif request.method == "OPTIONS":
        resp = HttpResponse('')
        resp['Access-Control-Allow-Headers'] = 'Content-Type'
    else:
        resp = HttpResponseBadRequest('')
    resp['Access-Control-Allow-Origin'] = 'http://localhost:3000'
    return resp

## Instruction:
Add error message to BadRequest signup response for invalid method
## Code After:
from django.http import JsonResponse, HttpResponse, HttpResponseBadRequest
from django.views.decorators.csrf import csrf_exempt
import json
from helpers import get_school_list, check_signup_email


def get_schools(request):
    resp = JsonResponse({'schools': get_school_list()})
    resp['Access-Control-Allow-Origin'] = 'http://localhost:3000'
    return resp


@csrf_exempt
def signup(request):
    if request.method == "POST":
        signup_parameters = json.loads(request.body.decode('utf-8'))
        if check_signup_email(signup_parameters['email']):
            resp = HttpResponse('Signup OK')
        else:
            resp = HttpResponseBadRequest('Invalid univesity email')
    elif request.method == "OPTIONS":
        resp = HttpResponse('')
        resp['Access-Control-Allow-Headers'] = 'Content-Type'
    else:
        resp = HttpResponseBadRequest('Invalid request method')
    resp['Access-Control-Allow-Origin'] = 'http://localhost:3000'
    return resp
