Created
October 24, 2011 12:06
-
-
Save aschem/1308865 to your computer and use it in GitHub Desktop.
Django cross-domain Ajax view decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import HttpResponse | |
ACC_HEADERS = {'Access-Control-Allow-Origin': '*', | |
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS', | |
'Access-Control-Max-Age': 1000, | |
'Access-Control-Allow-Headers': '*'} | |
def cross_domain_ajax(func): | |
""" Sets Access Control request headers.""" | |
def wrap(request, *args, **kwargs): | |
# Firefox sends 'OPTIONS' request for cross-domain javascript call. | |
if request.method != "OPTIONS": | |
response = func(request, *args, **kwargs) | |
else: | |
response = HttpResponse() | |
for k, v in ACC_HEADERS.iteritems(): | |
response[k] = v | |
return response | |
return wrap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment