<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 83 Flask設置和刪除cookie\|Flask設置cookie過期時間\|設置Cookie的有效域名 * 設置cookie:設置cookie在Response對象上進行設置的,通過"flask.Response"對象上的一個"set\_cookie\(\)"方法來進行設置cookie信息 ```text # response對象 resp = Response("name") # 設置cookie值 resp.set_cookie("name","value") ``` * 刪除cookie:通過"flask.Response"對象上的一個"delete\_cookie\(\)"方法來進行設置cookie信息 ```text # 刪除指定cookie resp.delete_cookie("name") ``` * 設置cookie的有效期,默認有效期:知道瀏覽器關閉為止 * 使用max\_age參數設置有效期事件 * ```text # max_age:距離多少秒后cookie值過期 resp.set_cookie("name","value",max_age=10) ``` * 使用expires參數 * ```text one: expires = datetime(year=2018,month=7,day=14,hour=16,minute=29,second=0) two: # 使用expires參數,就必須使用格林尼治時間 # 要相對北京時間少8個小時 expires = datetime(year=2018, month=7, day=14, hour=8, minute=29, second=0) three: # 設置距離多久 expires = datetime.now() + timedelta(seconds=1) - timedelta(hours=8) resp.set_cookie("name", "value", expires=expires) ``` * 注意:max\_age在IE8以下的瀏覽器是不支持的。expires在新班的http協議中被廢棄,但是到目前為止所有的瀏覽器都能夠支持它 * ```text @app.route('/') def hello_world(): # response對象 resp = Response("name") # # 設置cookie值 # max_age:距離多少秒后cookie值過期 # resp.set_cookie("name","value",max_age=10) # expires = datetime(year=2018,month=7,day=14,hour=16,minute=29,second=0) # 使用expires參數,就必須使用格林尼治時間 # 要相對北京時間少8個小時 # expires = datetime(year=2018, month=7, day=14, hour=8, minute=29, second=0) # 設置距離多久 # 在新版本的http協議中,expires參數視為廢棄 # 注意同時指定了expires參數和max_age參數,則使用max_age參數 expires = datetime.now() + timedelta(seconds=1) - timedelta(hours=8) resp.set_cookie("name", "value", expires=expires) # 刪除指定cookie # resp.delete_cookie("name") return resp # secure設置為True只能在HTTPS協議下使用 # httponly設置為Truecookie只能被瀏覽器讀取,不能被js讀取 # expires無效日期 # max_age:以秒為單位,距離現在多久過期 # set_cookie(self, key, value='', # max_age=None, expires=None, # path='/', domain=None, # secure=False, httponly=False, # samesite=None) ``` * 設置cookie的有效域名:cookie只能在主域名下使用。如果想要在子域名下使用,那么應該給"set\_cookie"傳遞一個"domain='.ty.com'"來指定其他子域名才能訪問到這個cookie信息。 1.定義藍圖 ```text cmsviews.py from flask import Blueprint cms = Blueprint("cms",name,subdomain="cms") @cms.route("/") def index(): return "cms 首頁" cookie.demo.py .... from cmsviews import cms # 注冊藍圖 app.register_blueprint(cms) app.config["SERVER_NAME"] = "ty.com:5000" .... ``` 2.地址映射:在hosts文件中添加以下映射 ```text 127.0.0.1 ty.com 127.0.0.1 cms.ty.com ``` 3.設置set\_cookie中的domain參數 ```text resp = Response("name") resp.set_cookie("name", "value",domain=".ty.com") ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看