[ The same-origin policy - Cross-domain problem ]
One 、django The default is the same origin policy , So the front and back stage are separated , visit django There will be CORS Error reporting for cross domain problems
Two 、 What is cross-domain
'''
i)ip Different : Taiwan before and after ( Two servers ) Not running on a single host
ii)port Different : Taiwan before and after ( Two servers ) It's independent of each other , Running on different ports
iii) Different agreements :http And https It is also a cross domain problem
notes : The three meet one , It's cross domain
'''
3、 ... and 、 To solve the cross domain
'''
i) camouflage : Disguise the foreground request as a request from the background
ii) The background actively allows cross domain : The background configuration allows cross domain ( Process... In the response header )
'''
Four 、Django To solve the cross domain
i) Install the module :
'''
pip install django-cors-headers
'''
ii) register app:
'''
INSTALLED_APPS = [
...
'corsheaders'
]
'''
iii) Add Middleware
'''
MIDDLEWARE = [
...
'corsheaders.middleware.CorsMiddleware'
]
'''
iv) Allow cross domain sources
'''
CORS_ORIGIN_ALLOW_ALL = True
'''
Be accomplished !!!!







