久久精品五月,日韩不卡视频在线观看,国产精品videossex久久发布 ,久久av综合

站長資訊網
最全最豐富的資訊網站

Python Flask大刀解決跨域問題

python視頻教程欄目為大家介紹Python Flask解決跨域問題。

Python Flask大刀解決跨域問題

系列文章目錄

Table of Contents

  • 系列文章目錄
  • 前言
  • 使用步驟
    • 1. 引入庫
    • 2. 配置
      • 1. 使用 CORS函數 配置全局路由
      • 2. 使用 @cross_origin 來配置單行路由
    • 配置參數說明
  • 總結
  • 參考

前言

我靠,又跨域了

使用步驟

1. 引入庫

pip install flask-cors復制代碼

2. 配置

flask-cors 有兩種用法,一種為全局使用,一種對指定的路由使用

1. 使用 CORS函數 配置全局路由

from flask import Flask, requestfrom flask_cors import CORS  app = Flask(__name__) CORS(app, supports_credentials=True)復制代碼

其中 CORS 提供了一些參數幫助我們定制一下操作。

常用的我們可以配置 origins、methodsallow_headerssupports_credentials

所有的配置項如下:

:param resources:     The series of regular expression and (optionally) associated CORS     options to be applied to the given resource path.      If the argument is a dictionary, it's keys must be regular expressions,     and the values must be a dictionary of kwargs, identical to the kwargs     of this function.      If the argument is a list, it is expected to be a list of regular     expressions, for which the app-wide configured options are applied.      If the argument is a string, it is expected to be a regular expression     for which the app-wide configured options are applied.      Default : Match all and apply app-level configuration  :type resources: dict, iterable or string  :param origins:     The origin, or list of origins to allow requests from.     The origin(s) may be regular expressions, case-sensitive strings,     or else an asterisk      Default : '*' :type origins: list, string or regex  :param methods:     The method or list of methods which the allowed origins are allowed to     access for non-simple requests.      Default : [GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE] :type methods: list or string  :param expose_headers:     The header or list which are safe to expose to the API of a CORS API     specification.      Default : None :type expose_headers: list or string  :param allow_headers:     The header or list of header field names which can be used when this     resource is accessed by allowed origins. The header(s) may be regular     expressions, case-sensitive strings, or else an asterisk.      Default : '*', allow all headers :type allow_headers: list, string or regex  :param supports_credentials:     Allows users to make authenticated requests. If true, injects the     `Access-Control-Allow-Credentials` header in responses. This allows     cookies and credentials to be submitted across domains.      :note: This option cannot be used in conjuction with a '*' origin      Default : False :type supports_credentials: bool  :param max_age:     The maximum time for which this CORS request maybe cached. This value     is set as the `Access-Control-Max-Age` header.      Default : None :type max_age: timedelta, integer, string or None  :param send_wildcard: If True, and the origins parameter is `*`, a wildcard     `Access-Control-Allow-Origin` header is sent, rather than the     request's `Origin` header.      Default : False :type send_wildcard: bool  :param vary_header:     If True, the header Vary: Origin will be returned as per the W3     implementation guidelines.      Setting this header when the `Access-Control-Allow-Origin` is     dynamically generated (e.g. when there is more than one allowed     origin, and an Origin than '*' is returned) informs CDNs and other     caches that the CORS headers are dynamic, and cannot be cached.      If False, the Vary header will never be injected or altered.      Default : True :type vary_header: bool復制代碼

2. 使用 @cross_origin 來配置單行路由

from flask import Flask, requestfrom flask_cors import cross_origin  app = Flask(__name__)@app.route('/')@cross_origin(supports_credentials=True)def hello():     name = request.args.get("name", "World")    return f'Hello, {name}!'復制代碼

其中 cross_originCORS 提供一些基本相同的參數。

常用的我們可以配置 originsmethods、allow_headers、supports_credentials

所有的配置項如下:

:param origins:     The origin, or list of origins to allow requests from.     The origin(s) may be regular expressions, case-sensitive strings,     or else an asterisk      Default : '*' :type origins: list, string or regex  :param methods:     The method or list of methods which the allowed origins are allowed to     access for non-simple requests.      Default : [GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE] :type methods: list or string  :param expose_headers:     The header or list which are safe to expose to the API of a CORS API     specification.      Default : None :type expose_headers: list or string  :param allow_headers:     The header or list of header field names which can be used when this     resource is accessed by allowed origins. The header(s) may be regular     expressions, case-sensitive strings, or else an asterisk.      Default : '*', allow all headers :type allow_headers: list, string or regex  :param supports_credentials:     Allows users to make authenticated requests. If true, injects the     `Access-Control-Allow-Credentials` header in responses. This allows     cookies and credentials to be submitted across domains.      :note: This option cannot be used in conjuction with a '*' origin      Default : False :type supports_credentials: bool  :param max_age:     The maximum time for which this CORS request maybe cached. This value     is set as the `Access-Control-Max-Age` header.      Default : None :type max_age: timedelta, integer, string or None  :param send_wildcard: If True, and the origins parameter is `*`, a wildcard     `Access-Control-Allow-Origin` header is sent, rather than the     request's `Origin` header.      Default : False :type send_wildcard: bool  :param vary_header:     If True, the header Vary: Origin will be returned as per the W3     implementation guidelines.      Setting this header when the `Access-Control-Allow-Origin` is     dynamically generated (e.g. when there is more than one allowed     origin, and an Origin than '*' is returned) informs CDNs and other     caches that the CORS headers are dynamic, and cannot be cached.      If False, the Vary header will never be injected or altered.      Default : True :type vary_header: bool  :param automatic_options:     Only applies to the `cross_origin` decorator. If True, Flask-CORS will     override Flask's default OPTIONS handling to return CORS headers for     OPTIONS requests.      Default : True :type automatic_options: bool復制代碼

配置參數說明

參數 類型 Head 默認 說明
resources 字典、迭代器或字符串 全部 配置允許跨域的路由接口
origins 列表、字符串或正則表達式 Access-Control-Allow-Origin * 配置允許跨域訪問的源
methods 列表、字符串 Access-Control-Allow-Methods [GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE] 配置跨域支持的請求方式
expose_headers 列表、字符串 Access-Control-Expose-Headers None 自定義請求響應的Head信息
allow_headers 列表、字符串或正則表達式 Access-Control-Request-Headers * 配置允許跨域的請求頭
supports_credentials 布爾值 Access-Control-Allow-Credentials False 是否允許請求發送cookie
max_age timedelta、整數、字符串 Access-Control-Max-Age None 預檢請求的有效時長

總結

在 flask 的跨域配置中,我們可以使用 flask-cors 來進行配置,其中 CORS 函數 用來做全局的配置, @cross_origin 來實現特定路由的配置。

贊(0)
分享到: 更多 (0)
?
網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號
久久精品五月,日韩不卡视频在线观看,国产精品videossex久久发布 ,久久av综合
国产极品一区| 亚洲狼人精品一区二区三区| 亚洲美女久久| 亚洲青青久久| 蜜臀av一区二区在线免费观看| 亚洲精品小说| 午夜日韩福利| 久久福利一区| 亚洲欧洲日韩| 日韩精品第一| 一本色道精品久久一区二区三区| 国产一区二区三区自拍| 亚洲精品一区二区妖精| 日韩制服丝袜av| 日本午夜精品久久久| 精品国产成人| 一区二区视频欧美| 亚洲精品裸体| 牛牛精品成人免费视频| 精品国产成人| 999久久久免费精品国产| 1024精品一区二区三区| 久久不射网站| 国产图片一区| 日韩福利一区| 亚洲专区欧美专区| 9久re热视频在线精品| 日韩一区中文| 高清久久一区| 免播放器亚洲一区| 精品三级国产| 国产免费成人| 国产日韩欧美三级| 久久影院一区| 国产欧美一区二区三区米奇| 日韩天堂在线| 欧美在线看片| 99精品小视频| 国产精品sm| 亚洲综合精品四区| 国产黄色精品| 天堂av在线| 91国内精品| 亚洲精品一二三区区别| 麻豆视频一区二区| 国产精品日韩| 国产suv精品一区| 亚欧成人精品| 91精品国产成人观看| 国产午夜精品一区在线观看| 久久精品国产68国产精品亚洲| 日韩欧美中文字幕在线视频| 国产精品久久观看| 亚洲香蕉久久| jizzjizz中国精品麻豆| 视频一区视频二区中文| 国产日本精品| 五月综合激情| 久久久久久色 | 久久久久伊人| 亚洲一卡久久| 久久精品国产一区二区| 亚洲一区成人| av在线最新| 99精品99| 欧美一区二区三区免费看| 国产精品美女| 免费一二一二在线视频 | 亚洲毛片在线| 亚洲韩日在线| 欧美freesex黑人又粗又大| 久久精品国产999大香线蕉| 日韩成人精品一区二区三区 | 伊人精品一区| bbw在线视频| 丝袜美腿高跟呻吟高潮一区| 中文字幕色婷婷在线视频| 91成人福利| 免费欧美日韩| 99精品视频在线| 在线手机中文字幕| 久久精品国产99国产| 日韩国产精品久久久久久亚洲| 国产亚洲在线| 一级欧洲+日本+国产| 久久一区二区中文字幕| 在线一区视频观看| 精品香蕉视频| 国产极品久久久久久久久波多结野 | 亚洲大片在线| 99精品美女| 久久精品中文| 欧美日韩国产精品一区二区亚洲| 久久五月天小说| 91精品亚洲| 欧美日韩中文字幕一区二区三区 | 日本欧美一区| 日韩av成人高清| 国产精品久一| 精品一区不卡| 日韩欧美午夜| 久久久久久婷| 成人自拍av| 午夜久久tv| 蜜臀精品一区二区三区在线观看| 伊人久久一区| 日本欧美在线| 久久精品免视看国产成人| 丰满少妇一区| 日韩不卡免费高清视频| 美女少妇全过程你懂的久久| 日韩视频久久| 中文字幕中文字幕精品| 日韩精品免费观看视频| 国产精品香蕉| 成人午夜网址| 国产精品一页| 久久中文字幕一区二区三区| 精品美女视频| 在线一区免费| 日韩视频二区| 久久精品97| 亚洲伦乱视频| 亚洲深夜福利在线观看| 亚洲一区二区日韩| 中文一区一区三区免费在线观 | 久久久久久美女精品| 国产伦精品一区二区三区千人斩| 四虎精品永久免费| 97成人在线| 精品三级在线| 伊人久久高清| 免费看日韩精品| 国产精品videossex久久发布| 国产精品视频一区二区三区四蜜臂| 久久精品国产亚洲aⅴ| 欧美国产91| 亚洲日韩视频| 精品久久影院| 蜜桃av.网站在线观看| 99国产精品视频免费观看一公开 | 国产精品成久久久久| 欧美特黄视频| 国产精品蜜月aⅴ在线| 99精品国产一区二区三区| 日韩精品一区二区三区中文在线 | 国产一区二区三区不卡av| 亚洲成人不卡| 国产视频一区免费看| 国产亚洲久久| 亚洲国内欧美| 国产美女视频一区二区| 国产a亚洲精品| 亚洲aa在线| 欧美亚洲日本精品| 综合精品一区| 国产欧美91| 久久久国产亚洲精品| 久久精品999| 精品捆绑调教一区二区三区| 蜜桃av一区二区| 国产自产自拍视频在线观看 | 捆绑调教美女网站视频一区 | 成人国产精品一区二区免费麻豆| 亚洲激情偷拍| 久久精品国产精品亚洲毛片| 99日韩精品| 国产成人精品一区二区三区在线| 一区在线观看| 水蜜桃精品av一区二区| 中文字幕日本一区二区| 国产精品久久久亚洲一区| 免费av一区| 欧美另类中文字幕| 亚洲特级毛片| 精品视频一区二区三区四区五区| 日韩一级不卡| av资源新版天堂在线| 日本欧美久久久久免费播放网| 欧美91视频| 蜜桃av在线播放| 国产a亚洲精品| 欧美aⅴ一区二区三区视频| 亚洲精品少妇| 日本欧美在线看| 99精品综合| 国产91在线播放精品| 国产日韩在线观看视频| 欧美专区18| 亚洲一级影院| 日韩精品一区二区三区免费观看| 麻豆久久一区| 国产伦精品一区二区三区视频| 亚洲欧美日韩国产一区二区| 久久国产主播| 久久久久久久久丰满| 日韩高清中文字幕一区二区| 老牛影视精品| 福利一区二区三区视频在线观看| 欧美国产另类|