CORS Python
pip install django-cors-headers
Fuck Coder
pip install django-cors-headers
def the_function(request):
# Return CORS headers on OPTIONS request.
if request.method == 'OPTIONS':
headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Max-Age': '3600'
}
return ('', 204, headers)
# If the request is GET then handle it normally
if request.method == 'GET':
x = request.args('x')
y = request.args('x')
result = int(x) * int(y)
headers = {
'Access-Control-Allow-Origin': '*'
}
return (result, 200, headers)
else:
# If the request is not GET or OPTIONS, deny.
return '', 400