<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Python weppy全棧的 Python Web 框架

          聯(lián)合創(chuàng)作 · 2023-09-20 06:04

          weppy 是一個(gè)全棧的 Python Web 框架,weppy 非常靈巧,易于理解學(xué)習(xí)和使用。兼容 Python 2.7, 3.3, 3.4, 3.5 和 3.6.

          示例代碼:

          from weppy import App, request, response
          from weppy.orm import Database, Model, Field
          from weppy.tools import service, requires
          
          class Task(Model):
              name = Field('string')
              is_completed = Field('bool', default=False)
          
          app = App(__name__)
          app.config.db.uri = "postgres://user:password@localhost/foo"
          db = Database(app)
          db.define_models(Task)
          app.pipeline = [db.pipe]
          
          def is_authenticated():
              return request.headers["Api-Key"] == "foobar"
          
          def not_authorized():
              response.status = 401
              return {'error': 'not authorized'}
          
          @app.route(methods='get')
          @service.json
          @requires(is_authenticated, otherwise=not_authorized)
          def todo():
              page = request.query_params.page or 1
              tasks = Task.where(
                  lambda t: t.is_completed == False
              ).select(paginate=(page, 20))
              return {'tasks': tasks}

          weppy 可以讓你直接用 Python 編寫模板:

          {{extend 'layout.html'}}
          
          <div class="post-list">
          {{for post in posts:}}
              <div class="post">
                  <h2>{{=post.title}}</h2>
              </div>
          {{pass}}
          {{if not posts:}}
              <div>
                  <em>No posts here so far.</em>
              </div>
          {{pass}}
          </div>













          瀏覽 17
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  中文字幕第五页在线观看 | 高清无码免费在线 | 涩涩蜜桃视频在线观看 | 无码人妻免费视频 | 最新亚洲黄色视频 |