3

Django: CORS for a View

 3 years ago
source link: https://snakeycode.wordpress.com/2020/11/27/django-cors-for-a-view/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Django: CORS for a View

Let’s say you have a few views that return data and you want to make them available from any domain. Here is how to do it (from SO):

response = JsonResponse(data)
response["Access-Control-Allow-Origin"] = "*"
response["Access-Control-Allow-Methods"] = "GET, OPTIONS"
response["Access-Control-Max-Age"] = "1000"
response["Access-Control-Allow-Headers"] = "X-Requested-With, Content-Type"
return response

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK