当前位置:网站首页>[same origin policy - cross domain issues]

[same origin policy - cross domain issues]

2022-06-23 21:40:00 Liu Jiaoshou

[ 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 !!!!

原网站

版权声明
本文为[Liu Jiaoshou]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206232055361443.html