銆愯浆銆戝悓婧愮瓥鐣ュ拰璺ㄥ煙璇锋眰瑙e喅鏂规

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了銆愯浆銆戝悓婧愮瓥鐣ュ拰璺ㄥ煙璇锋眰瑙e喅鏂规相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e7%a7%bb%e9%99%a4' title='绉婚櫎'>绉婚櫎   鍒锋柊   cdn   cep   鍒╃敤   pdo   OLE   tar   瀹氬悜   

涓€銆佷竴涓簮鐨勫畾涔?/h1>

濡傛灉涓や釜椤甸潰鐨勫崗璁紝绔彛锛堝鏋滄湁鎸囧畾锛夊拰鍩熷悕閮界浉鍚岋紝鍒欎袱涓〉闈㈠叿鏈夌浉鍚岀殑婧愩€?br />涓句釜渚嬪瓙锛?/p>

      涓嬭〃缁欏嚭浜嗙浉瀵筯ttp://a.xyz.com/dir/page.html鍚屾簮妫€娴嬬殑绀轰緥: 
      URL                                         缁撴灉          鍘熷洜
      http://a.xyz.com/dir2/other.html            鎴愬姛     鍗忚锛岀鍙o紙濡傛灉鏈夋寚瀹氾級鍜屽煙鍚嶉兘鐩稿悓
      http://a.xyz.com/dir/inner/another.html     鎴愬姛    鍗忚锛岀鍙o紙濡傛灉鏈夋寚瀹氾級鍜屽煙鍚嶉兘鐩稿悓 
      https://a.xyz.com/secure.html               澶辫触    涓嶅悓鍗忚 ( https鍜宧ttp )
      http://a.xyz.com:81/dir/etc.html            澶辫触    涓嶅悓绔彛 ( 81鍜?0)
      http://a.opq.com/dir/other.html             澶辫触    涓嶅悓鍩熷悕 ( xyz鍜宱pq)

 

浜屻€佸悓婧愮瓥鐣ユ槸浠€涔堬紵

鍚屾簮绛栫暐鏄祻瑙堝櫒鐨勪竴涓畨鍏ㄥ姛鑳斤紝涓嶅悓婧愮殑瀹㈡埛绔剼鏈湪娌℃湁鏄庣‘鎺堟潈鐨勬儏鍐典笅锛屼笉鑳借鍐欏鏂硅祫婧愩€傛墍浠yz.com涓嬬殑js鑴氭湰閲囩敤ajax璇诲彇abc.com閲岄潰鐨勬枃浠舵暟鎹槸浼氳鎷掔粷鐨勩€?/p>

鍚屾簮绛栫暐闄愬埗浜嗕粠鍚屼竴涓簮鍔犺浇鐨勬枃妗f垨鑴氭湰濡備綍涓庢潵鑷彟涓€涓簮鐨勮祫婧愯繘琛屼氦浜掋€傝繖鏄竴涓敤浜庨殧绂绘綔鍦ㄦ伓鎰忔枃浠剁殑閲嶈瀹夊叏鏈哄埗銆?/p>

涓夈€佸熀浜巎sonp瀹炵幇鐨勮法鍩熻姹?/h1>
  1. 椤甸潰涓殑閾炬帴锛岄噸瀹氬悜浠ュ強琛ㄥ崟鎻愪氦鏄笉浼氬彈鍒板悓婧愮瓥鐣ラ檺鍒剁殑銆?/p>

  2. 璺ㄥ煙璧勬簮鐨勫紩鍏ユ槸鍙互鐨勩€備絾鏄痡s涓嶈兘璇诲啓鍔犺浇鐨勫唴瀹广€傚宓屽叆鍒伴〉闈腑鐨?lt;script src="..."></script>锛?lt;img>锛?lt;link>锛?lt;iframe>绛夈€?/p>

涓嬮潰鏉ュ垎姝ヤ妇渚嬭缁嗛槓杩板叾涓殑濂ュ锛?/p>

1銆佸厛寮€涓や釜椤圭洰锛?/h3>

椤圭洰1锛坔ttp://127.0.0.1:8000/锛?br />椤圭洰2锛坔ttp://127.0.0.1:8100/锛?/p>

椤圭洰1

url锛?
url(r鈥榠ndex1/$鈥?span style="color: #000000;">,views.index1)

views锛?

def index1(request):
return  HttpResponse(鈥榳angjifei鈥?

 

椤圭洰2

url锛?
url(r鈥榠ndex2/$鈥?views.index2)

views  锛?
def index2(request):
    return render(request,鈥榠ndex2.html鈥?

index2.html锛?
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鍚屾簮绛栫暐</title>
</head>
<body>

<button id="btn">鎻愪氦</button>

<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js">    </script>
<script>
    $(鈥?/span>#btn鈥?/span>).click(function () {
        $.ajax({
            url:"http://127.0.0.1:8000/index1/",
            type:鈥?/span>get鈥?/span>,
            success:function (res) {
                console.log(res)
           }
        })
    })
</script>
</body>
</html>

 

鐜板湪锛屾墦寮€浣跨敤娴忚鍣ㄦ墦寮€ http://127.0.0.1:8100/index2/锛岀偣鍑婚〉闈笂鐨?鈥樻彁浜も€?鎸夐挳锛屼細鍦╟onsole椤甸潰鍙戠幇閿欒淇℃伅濡備笅锛?/p>

 
鎶€鏈浘鐗? src=

 

涓轰粈涔堟姤閿欏憿锛熷洜涓哄悓婧愮瓥鐣ラ檺鍒惰法鍩熷彂閫乤jax璇锋眰銆?br />缁嗗績鐐圭殑鍚屽搴旇浼氬彂鐜版垜浠殑demo1椤圭洰鍏跺疄宸茬粡鎺ユ敹鍒颁簡璇锋眰骞惰繑鍥炰簡鍝嶅簲锛屾槸娴忚鍣ㄥ闈炲悓婧愯姹傝繑鍥炵殑缁撴灉鍋氫簡鎷︽埅銆?br />鍐嶇粏蹇冪偣鐨勫悓瀛︿細鍙戠幇锛屾垜浠娇鐢╟dn鏂瑰紡寮曠敤鐨刯Query鏂囦欢涔熸槸璺ㄥ煙鐨勶紝瀹冨氨鍙互浣跨敤銆?br />鍚屾牱鏄粠鍏朵粬鐨勭珯鐐规嬁涓滆タ锛宻cript鏍囩灏卞彲浠ャ€傞偅鎴戜滑鑳戒笉鑳藉埄鐢ㄨ繖涓€鐐规悶鐐逛簨鎯呭憿锛?/p>

2銆佹妸index2.html涓殑浠g爜鏀逛竴涓嬶細

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鍚屾簮绛栫暐</title>
</head>
<body>

<button id="btn">鎻愪氦</button>

<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js">    </script>
<script src="http://127.0.0.1:8000/index1/"></script>
</body>
</html>

 

鐜板湪鍒锋柊涓€涓嬩細鍑虹幇濡備笅閿欒锛?/p>

 

 
鎶€鏈浘鐗? src=
 

鐪嬫潵鍚庣杩斿洖鐨勫搷搴斿凡缁忚鎷垮埌浜嗭紝鍙笉杩囨妸wangjifei褰撴垚浜嗕竴涓彉閲忔潵浣跨敤锛屼絾鏄椤甸潰涓婂嵈娌℃湁瀹氫箟涓€涓悕涓簑angjifei鐨勫彉閲忋€傛墍浠ュ嚭閿欎簡銆?/p>

3銆侀偅鎴戜滑灏卞湪index2.html涓畾涔変竴涓獁angjifei鍙橀噺鐪嬬湅锛?/h3>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鍚屾簮绛栫暐</title>
</head>
<body>

<button id="btn">鎻愪氦</button>

<script>
    var wangjifei = 123
</script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js">    </script>
<script src="http://127.0.0.1:8000/index1/"></script>
</body>
</html>

 

鍒锋柊鍙戠幇涓嶆姤閿欎簡锛?/p>

 

 
鎶€鏈浘鐗? src=

4銆佹垜瀹氫箟涓€涓彉閲忓彲浠ワ紝閭e彲涓嶅彲浠ュ畾涔変竴涓嚱鏁板憿锛?/h3>

index2.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鍚屾簮绛栫暐</title>
</head>
<body>

<button id="btn">鎻愪氦</button>

<script>
    function wangjifei() {
        console.log(鈥?/span>鍑烘墜灏辫涓撲笟鈥?/span>)
    }
</script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js">    </script>
<script src="http://127.0.0.1:8000/index1/"></script>
</body>
</html>

 

椤圭洰1涓殑views锛氫篃淇敼涓€涓?/p>

def index1(request):
return  HttpResponse(鈥榳angjifei()鈥?

 

鍒锋柊涓€涓嬮〉闈㈡樉绀虹粨鏋滐細

 

 
鎶€鏈浘鐗? src=

 

缁撴灉鍒嗘瀽锛氳繑鍥炵殑 wangjifei()锛岄〉闈笂鎷垮埌杩欎釜鍝嶅簲涔嬪悗鐩存帴鎵ц浜唚angjifei鍑芥暟锛?/p>

5銆侀偅鍑芥暟涓彲涓嶅彲浠ヤ紶閫掑弬鏁板憿锛熸垜浠瘯涓€涓嬶紒

index2.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鍚屾簮绛栫暐</title>
</head>
<body>

<button id="btn">鎻愪氦</button>

<script>
    function wangjifei(res) {
         console.log(res)
    }
</script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js">    </script>
<script src="http://127.0.0.1:8000/index1/"></script>
</body>
</html>

 

椤圭洰1涓殑 views

from django.http import HttpResponse
import json

def index1(request):
    ret={鈥榗ode鈥?1,鈥榤sg鈥?[110,119,120,12306]}
    res = json.dumps(ret)
    return  HttpResponse(f鈥榳angjifei({res})鈥?

 

鍒锋柊涔嬪悗鏄剧ず缁撴灉锛?/p>

 

 
鎶€鏈浘鐗? src=

鏋滅劧浼犻€掑弬鏁颁篃鏄彲浠ョ殑锛佹垜浠€氳繃script鏍囩鐨勮法鍩熺壒鎬ф潵缁曡繃鍚屾簮绛栫暐鎷垮埌鎯宠鐨勬暟鎹簡锛侊紒锛?/p>

杩欏叾瀹炲氨鏄疛SONP鐨勭畝鍗曞疄鐜版ā寮忥紝鎴栬€呰鏄疛SONP鐨勫師鍨嬶細鍒涘缓涓€涓洖璋冨嚱鏁帮紝鐒跺悗鍦ㄨ繙绋嬫湇鍔′笂璋冪敤杩欎釜鍑芥暟骞朵笖灏咼SON 鏁版嵁褰㈠紡浣滀负鍙傛暟浼犻€掞紝瀹屾垚鍥炶皟銆?br />灏咼SON鏁版嵁濉厖杩涘洖璋冨嚱鏁帮紝杩欏氨鏄疛SONP鐨凧SON+Padding鐨勫惈涔夈€?br />浣嗘槸鎴戜滑鏇村鏃跺€欐槸甯屾湜閫氳繃浜嬩欢瑙﹀彂鏁版嵁鐨勮幏鍙栵紝鑰屼笉鏄儚涓婇潰涓€鏍烽〉闈竴鍒锋柊灏辨墽琛屼簡锛岃繖鏍峰緢涓嶇伒娲汇€?/p>

6銆佹垜浠彲浠ラ€氳繃javascript鍔ㄦ€佺殑鍒涘缓script鏍囩鏉ュ疄鐜般€?/h3>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鍚屾簮绛栫暐</title>
</head>
<body>

<button id="btn">鎻愪氦</button>

<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js">    </script>
<script>
    //鑷畾涔夌殑鍑芥暟
    function wangjifei(res) {
        console.log(res)
    }
    //jquery缁檅utton缁戝畾鐐瑰嚮浜嬩欢
    $(鈥?btn鈥?.click(function () {
        //鍒涘缓涓€涓猻cript鏍囩
        var scriptEle = document.createElement(鈥榮cript鈥?span style="color: #000000;">);
        //缁欐爣绛炬坊鍔爏rc灞炴€э紝骞舵坊鍔犲搴旂殑灞炴€у€?   http://127.0.0.1:8000/index1
        $(scriptEle).attr(鈥榮rc鈥?鈥榟ttp://127.0.0.1:8000/index1鈥?span style="color: #000000;">);
        //灏嗗垱寤哄ソ鐨勬爣绛炬坊鍔犲埌椤甸潰涓紝鏍囩娣诲姞鍚庡氨浼氳嚜鍔ㄨЕ鍙慻et璇锋眰
        $(鈥榖ody鈥?span style="color: #000000;">).append(scriptEle);
        //灏嗘爣绛剧Щ闄?/span>
        $(scriptEle).remove()
    })
</script>
</body>
</html>

 

杩欐牱褰撴垜浠偣鍑籦utton鎸夐挳鐨勬椂鍊欙紝浼氬湪椤甸潰涓婃彃鍏ヤ竴涓猻cript鏍囩锛岀劧鍚庝粠鍚庣鑾峰彇鏁版嵁鍚庡啀鍒犻櫎鎺夈€?/p>

7銆佷负浜嗗疄鐜版洿鍔犵伒娲荤殑璋冪敤锛屾垜浠彲浠ユ妸瀹㈡埛绔畾涔夌殑鍥炶皟鍑芥暟鐨勫嚱鏁板悕浼犵粰鏈嶅姟绔紝鏈嶅姟绔垯浼氳繑鍥炰互璇ュ洖璋冨嚱鏁板悕锛屽皢鑾峰彇鐨刯son鏁版嵁浼犲叆杩欎釜鍑芥暟瀹屾垚鍥炶皟銆傝繖鏍峰氨鑳藉疄鐜板姩鎬佺殑璋冪敤浜嗐€備慨鏀逛唬鐮佸涓?

index2.html浠g爜锛?/p>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鍚屾簮绛栫暐</title>
</head>
<body>

<button id="btn">鎻愪氦</button>

<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js">    </script>
<script>
    //鑷畾涔夌殑鍑芥暟
    function xxx(res) {
        console.log(res)
    }
    //jquery缁檅utton缁戝畾鐐瑰嚮浜嬩欢
    $(鈥?/span>#btn鈥?/span>).click(function () {
        //鍒涘缓涓€涓猻cript鏍囩
        var scriptEle = document.createElement(鈥?/span>script鈥?/span>);
        //缁欐爣绛炬坊鍔爏rc灞炴€э紝骞舵坊鍔犲搴旂殑灞炴€у€?   http://127.0.0.1:8000/index1锛焎allback=xxx
        $(scriptEle).attr(鈥?/span>src鈥?/span>,鈥?/span>http://127.0.0.1:8000/index1?callback=xxx鈥?/span>);
        //灏嗗垱寤哄ソ鐨勬爣绛炬坊鍔犲埌椤甸潰涓紝鏍囩娣诲姞鍚庡氨浼氳嚜鍔ㄨЕ鍙慻et璇锋眰
        $(鈥?/span>body鈥?/span>).append(scriptEle);
        //灏嗘爣绛剧Щ闄?/span>
        $(scriptEle).remove()
    })
</script>
</body>
</html>

 

椤圭洰1涓璿iews锛?/p>

from django.http import HttpResponse
import json

def index1(request):
    ret={鈥榗ode鈥?1,鈥榤sg鈥?[110,119,120,12306]}
    res = json.dumps(ret)
    callback = request.GET.get(鈥榗allback鈥?span style="color: #000000;">)
    return  HttpResponse(f鈥榹callback}({res})鈥?

 

鍥涖€乯Query涓璯etJSON鏂规硶浠嬬粛锛?/h1>

1銆乯Query涓湁涓撻棬鐨勬柟娉曞疄鐜癹sonp銆?/h3>

index2.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鍚屾簮绛栫暐</title>
</head>
<body>
<button id="btn">鎻愪氦</button>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js">        </script>
<script>
    //jquery缁檅utton缁戝畾鐐瑰嚮浜嬩欢
    $(鈥?/span>#btn鈥?/span>).click(function () {
        $.getJSON("http://127.0.0.1:8000/index1?callback=?",function (res) {
            console.log(res)
        })
    })
</script>
</body>
</html>

 

瑕佹敞鎰忕殑鏄湪url鐨勫悗闈㈠繀椤昏鏈変竴涓猚allback鍙傛暟锛岃繖鏍穏etJSON鏂规硶鎵嶄細鐭ラ亾鏄敤JSONP鏂瑰紡鍘昏闂湇鍔★紝callback鍚庨潰鐨勯偅涓紵鏄痡Query鍐呴儴鑷姩鐢熸垚鐨勪竴涓洖璋冨嚱鏁板悕銆?/p>

2銆佷絾鏄鏋滄垜浠兂鑷繁鎸囧畾鍥炶皟鍑芥暟鍚嶏紝鎴栬€呰鏈嶅姟涓婅瀹氫簡鍥炶皟鍑芥暟鍚嶈鎬庝箞鍔炲憿锛熸垜浠彲浠ヤ娇鐢?.ajax鏂规硶鏉ュ疄鐜帮細

index2.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鍚屾簮绛栫暐</title>
</head>
<body>
<button id="btn">鎻愪氦</button>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js">    </script>
<script>
    //jquery缁檅utton缁戝畾鐐瑰嚮浜嬩欢
    $(鈥?/span>#btn鈥?/span>).click(function () {
        $.ajax({
            //瑕佽闂殑url
            url:"http://127.0.0.1:8000/index1/",
            //瑕佸鐞嗙殑鏁版嵁绫诲瀷jsonp
            dataType:鈥?/span>jsonp鈥?/span>,
            //鑷畾涔夊洖璋冨嚱鏁板悕蹇呰鍙傛暟
            jsonp:鈥?/span>callback鈥?/span>,
            //鑷畾涔夊洖璋冨嚱鏁板悕锛寀rl涓璫allback=鍚庨潰鐨勫嚱鏁板悕
            jsonpcallback:鈥?/span>wangjifei鈥?/span>
        })
    });
    //鍥炶皟鍑芥暟
    function wangjifei(res) {
        console.log(res)
    }
</script>
</body>
</html>

 

views:

from django.http import HttpResponse
import json

def index1(request):
    ret={鈥榗ode鈥?1,鈥榤sg鈥?[110,119,120,12306]}
    res = json.dumps(ret)
    callback = request.GET.get(鈥榗allback鈥?span style="color: #000000;">)
    return  HttpResponse(f鈥榳angjifei({res})鈥?

 

3銆佺敤ajax鎶€鏈€氬父灏嗗洖璋冨嚱鏁板啓鍦ㄦ垚鍔熷洖璋冨嚱鏁扮殑浣嶇疆锛?/h3>

index2.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鍚屾簮绛栫暐</title>
</head>
<body>
<button id="btn">鎻愪氦</button>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js">    </script>
<script>
    //jquery缁檅utton缁戝畾鐐瑰嚮浜嬩欢
    $(鈥?/span>#btn鈥?/span>).click(function () {
        $.ajax({
            //瑕佽闂殑url
            url:"http://127.0.0.1:8000/index1/",
            //瑕佸鐞嗙殑鏁版嵁绫诲瀷jsonp
            dataType:鈥?/span>jsonp鈥?/span>,
            //success鍥炶皟
            success:function (res) {
                console.log(res)
            }
        })
    });
    //鍥炶皟鍑芥暟
    function wangjifei(res) {
        console.log(res)
    }
</script>
</body>
</html>

 

鏈€鍚庢潵涓€涓猨sonp鐨勫疄闄呭簲鐢細

 <!DOCTYPE html>
     <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>鍚屾簮绛栫暐</title>
    </head>
    <body>
    <button id="show-tv">鎻愪氦</button>
    <div class="tv-list"></div>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <script>
        $("#show-tv").click(function () {
            $.ajax({
                url: "http://www.jxntv.cn/data/jmd-jxtv2.html?  callback=list&_=1454376870403",
                dataType: 鈥?/span>jsonp鈥?/span>,
                jsonp: 鈥?/span>callback鈥?/span>,
                jsonpCallback: 鈥?/span>list鈥?/span>,
                success: function (data) {
                    var weekList = data.data;
                    console.log(weekList);
                    var $tvListEle = $(".tv-list");
                    $.each(weekList, function (k, v) {
                        var s1 = "<p>" + v.week + "鍒楄〃</p>";
                        $tvListEle.append(s1);
                        $.each(v.list, function (k2, v2) {
                            var s2 = "<p><a href=鈥?/span>" + v2.link + "鈥?gt;" + v2.name + "</a></p>";
                            $tvListEle.append(s2)
                        });
                        $tvListEle.append("<hr>");
                    })
                }
            })
        });
    </script>
    </body>
    </html>

 

浜斻€佸熀浜嶤ore鏂规硶瑙e喅璺ㄥ煙璇锋眰

  • 鎴戜滑浠嬬粛浜唈sonp瑙e喅璺ㄥ煙璇锋眰闂锛岃繖绉嶈В鍐虫柟寮忓緢濂界殑璇犻噴浜嗚法鍩熻姹傜殑鏈川锛屼絾鏄暐鏄鹃夯鐑︼紝鏄惁杩樿寰楀湪鎴戜滑涓嶅仛浠讳綍澶勭悊鐨勬椂鍊欙紝璺ㄥ煙璇锋眰鏃跺€欐祻瑙堝櫒缁欐垜浠姤鐨勯敊璇笉锛熺炕璇戣繃鏉ュ氨鏄洜涓哄搷搴斿ご娌℃湁鎸囧畾Access-Control-Allow-Origin鎵€鍏佽鍘熷鐨勮姹傝矾寰勶紝鍥犳鍘熷璇锋眰璺緞http://127.0.0.1:8001涓嶈鍏佽璁块棶銆?鍩轰簬涓婅堪鐨勫師鍥犺В閲婏紝鎴戜滑鍙渶瑕佸湪鍝嶅簲鐨勫唴瀹瑰姞鍏ヤ笂杩拌繖鏍风殑鎺堟潈瀛楁锛屼究鍙В鍐炽€?/p>

  • 绠€鍗曡姹傜殑瀹氫箟锛?br />鍙鍚屾椂婊¤冻浠ヤ笅涓ゅぇ鏉′欢锛屽氨灞炰簬绠€鍗曡姹?涓嶆弧瓒冲氨鏄鏉傝姹傦紒锛侊紒
    1.锛?锛?璇锋眰鏂规硶鏄互涓嬩笁绉嶆柟娉曚箣涓€锛?br />-- HEAD锛孏ET锛孭OST
    2.锛?锛塇TTP鐨勫ご淇℃伅涓嶈秴鍑轰互涓嬪嚑绉嶅瓧娈碉細
    -- Accept
    -- Accept-Language
    -- Content-Language
    -- Last-Event-ID
    -- Content-Type锛氬彧闄愪簬涓変釜鍊糰pplication/x-www-form-urlencoded銆乵ultipart/form-data銆乼ext/plain

鐢变簬django鐨勬墍鏈夎姹傚搷搴旈兘瑕佽蛋涓棿浠讹紝鎵€浠ュ彲浠ュ啓涓€涓法鍩熺殑涓棿浠舵潵瑙e喅璺ㄥ煙闂

from django.utils.deprecation import MiddlewareMixin
class MyCore(MiddlewareMixin):
    def process_response(self, request, response):
        response[鈥楢ccess-Control-Allow-Origin鈥榏 = "*"  //绠€鍗曡姹?/span>
        if request.method == "OPTIONS":
            # 澶嶆潅璇锋眰 棰勬
            response[鈥楢ccess-Control-Allow-Headers鈥榏 = "Content-Type"
            response[鈥楢ccess-Control-Allow-Methods鈥榏 = "POST, DELETE, PUT"
        return response

 

 
 
鍘熸枃鍑哄锛?a href="https://www.jianshu.com/p/bce07495b77c">https://www.jianshu.com/p/bce07495b77c
 
 

以上是关于銆愯浆銆戝悓婧愮瓥鐣ュ拰璺ㄥ煙璇锋眰瑙e喅鏂规的主要内容,如果未能解决你的问题,请参考以下文章

django瑙e喅璺ㄥ煙闂

銆愯浆銆慾ava.io.Closeable鎺ュ彛

銆愯浆銆?springBoot---蹇€熷垱寤洪」鐩紝鍒濊Вjackson

銆愯浆銆戙€怱alesfoece銆慉pproval Process 鍦?Apex 涓殑浣跨敤

銆愯浆銆?springboot鏁村悎redis-sentinel鏀寔Cache娉ㄨВ

銆愯浆銆慔Base涓璟ookeeper锛孯egionServer锛孧aster锛孋lient涔嬮棿鍏崇郴