<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之旅 廣告
                # 21 自定義時間處理過濾器案例 ```text from flask import Flask,render_template from datetime import datetime app = Flask(__name__) app.config['TEMPLATES_AUTO_RELOAD'] = True # @app.route('/') # def hello_world(): # return render_template('index.html',position="-9") @app.route('/') def index(): context = { 'position':-9, # 'signature':None, 'signature': 1, 'article':'hello zhiliao world hello', # 'create_time':datetime.now(), 'create_time': datetime(2018,4,27,23,14,0), } signature = 1 a = signature or '默認值' return render_template('index.html',**context) # 指定一個名字 @app.template_filter('my_cut') def cut(value): value = value.replace("hello",'') return value @app.template_filter('handle_time') def handle_time(time): """ time 距離現在的時間是多少 如果時間間隔小于1分鐘以內,那么就顯示'剛剛' 如果是大于1分鐘小于等于1小時以內,那么就顯示'xx分鐘前' 如果是大于1小時小于等于24小時內,那么就顯示'xx小時前' 如果大于24小時小于30天以內,那么就顯示'xx天前' 否則就是具體時間:例2017年10月20日 :param time: :return: """ if isinstance(time,datetime): now = datetime.now() # 兩個時間相減,得到描述 timestamp = (now - time).total_seconds() if timestamp < 60: return '剛剛' elif timestamp < 60*60 and timestamp >= 60: minutes = timestamp/60 return "%s 分鐘前" % int(minutes) elif timestamp >= 60*60 and timestamp < 60*60*24: hours = timestamp/(60*60) return "%s 小時前" % int(hours) elif timestamp>= 60*60*24 and timestamp < 60*60*24*30: days = timestamp / (60*60*24) return "%s 天前" % int(days) else: return time.strftime('%Y/%m/%d %H:%M') else: return time if __name__ == '__main__': app.run(debug=True) **************************************************** <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>MIKU</title> </head> <body> {# <p>位置的絕對值是:{{ position }}</p>#} {# <p>位置的絕對值是:{{ position|wordcount }}</p>#} {# <p>個性簽名:{{ signature|default('Angle','boolean')}}</p>#} {# <p>個性簽名:{{ signature|default('Angle',boolean=True)}}</p>#} {# <p>個性簽名:{{ signature or 'angle'}}</p>#} {# <p>{{ article|my_cut }}</p>#} {# <p>{{ article}}</p>#} <p>發表時間:{{ create_time|handle_time }}</p> </body> </html> ```
                  <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>

                              哎呀哎呀视频在线观看