全栈的 Python Web 框架 Python weppy

码农软件 · 软件分类 · Web框架 · 2019-03-25 15:59:20

软件介绍

weppy 是一个全栈的 Python Web 框架,weppy 非常灵巧,易于理解学习和使用。兼容 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>













本文地址:https://codercto.com/soft/d/2131.html

Game Programming Patterns

Game Programming Patterns

Robert Nystrom / Genever Benning / 2014-11-2 / USD 39.95

The biggest challenge facing many game programmers is completing their game. Most game projects fizzle out, overwhelmed by the complexity of their own code. Game Programming Patterns tackles that exac......一起来看看 《Game Programming Patterns》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具