Skip to content
Advertisement

Access-Control-Allow-Origin in Django app

I’m developing a Phonegap app for my Django based app, but when trying to make Ajax calls I get this error:

JavaScript

How can I make it so my Django app allows cross origin for some urls?

Here’s my Ajax code:

JavaScript

Advertisement

Answer

Django by default does not provide the headers necessary to provide cross origin. The easiest way would be to just use this Django app that handles it for you: https://github.com/adamchainz/django-cors-headers

  • Add to installed apps
  • Add to middleware
  • Then stuff like…
JavaScript

to support allowing all, just use the setting… CORS_ALLOW_ALL_ORIGINS = True and then do any filtering of the request in middleware or in the view.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement