python的简单、快速、易生成的web框架
pythononwheels的Python项目详细描述
POW徽标
python3的快速而简单的生成webframework。准备出发!
Based on the ruby on rails principles. Generators for models/controllers/views/migrations…, convention over configuration, and PoW gets out of the way if you want it.
你好,世界
@app.make_routes() class HelloHandler(BaseHandler): @route(r'/hello', dispatch=["get"]) def hello(self): self.write("Hello world!")
安装:
pip install -U pythononwheels
船上需要的一切。包括电池。
PythonOnWheels是生成的, 快速应用程序开发,python的非侵入式web框架。 你不需要额外的工具来开始。从数据库到web服务器和 包括模板引擎。但你不是被迫使用它们 直接或轻松地包含您选择的模块和工具工具 只要你愿意。
基于一个很强的基础:
- python 3.x
- tornado网络服务器
- 支持的SQL数据库
- sql:sqlalchemyorm(sqlite,mysql, PostgreSQL、MS-SQL、Oracle等…)
- 在 场景
- NoSQL: tinyDB, MongoDB, elasticsearch
- cerberus模式和 船上验证
- 龙卷风模板
- css框架:bootstrap4和 semanticUI
可能是最简单的sql关系了!
基于sqlalchemy。使用pythononwheels只需添加一个类 喜欢装饰的人
@relation.has_many("comments") class Post(Base): # All your Post model code below here .. .....
对于您的sql post模型,每个post都可以有注释。会的 自动映射到数据库(sqlite,postgres,mysql,mariadb, Oracle、MSSQL…)和所有相关的注释模型。数据库迁移是 在后台自动创建。
支持的关系类型是:
- 有很多(“评论”)(装饰类有很多评论。)
- 多对多(“评论”)(装饰类有多对多 注释)
- 归属于(“comments”)(修饰类属于comments.)
- 一对一(“评论”)(装饰类有一对一 注释)
- tree()(修饰类具有邻接列表(是树)
所有POW模型(SQL或NoSQL)都使用cerberus模式作为定义。
这意味着您可以对每个模型进行验证,并且可以轻松地从sql切换到nosql
- @relation.setup\u schema()修饰符将此架构映射到
可用的sqlalchemy(或特定的nosql)列定义集。
- 仅限sql:model也将自动获得
创建has-many的外部键和python属性
与注释模型的关系。这一切都是为了你
@relation.has_many(“comments”)@relation.has_many(“comments”)
@relation.setup_schema()
class Post(Base):
#
# Schema definition with the new (cerberus) schema style
# which offer you immediate validation
#
schema = {
# string sqltypes can be TEXT or UNICODE or nothing
'author': {'type': 'string', 'maxlength' : 35 },
'title' : {'type': 'string', "required" : True },
'text' : {'type': 'string' },
'votes' : {'type': 'integer' },
'status': {'type': 'string', "allowed" : ["backlog", "wip", "done"] },
}
# init
def __init__(self, **kwargs):
self.init_on_load(**kwargs)
# your methods down here
可能是最简单的重新安排了!一个装饰工。完成!
使用pythononwheels,您只需添加一个类装饰符,比如
@app.add_rest_routes("basename")
将所有典型的rest路由映射到 根据处理程序类的crud方法。
顺便说一下:这是使用–rest参数时generate_handler为您生成的内容:
@app.add_rest_routes("rest_test") class RestTest(BaseHandler): # # every pow handler automatically gets these RESTful routes # when you add the : app.add_rest_routes() decorator. # # 1 GET /resttest #=> list # 2 GET /resttest/<uuid:identifier> #=> show # 3 GET /resttest/new #=> new # 4 GET /resttest/<uuid:identifier>/edit #=> edit # 5 GET /resttest/page/<uuid:identifier> #=> page # 6 GET /resttest/search #=> search # 7 PUT /resttest/<uuid:identifier> #=> update # 8 PUT /resttest #=> update (You have to send the id as json payload) # 9 POST /resttest #=> create # 10 DELETE /resttest/<uuid:identifier> #=> destroy # ...
路由:包括正则表达式和类似烧瓶的路由。
只需向处理程序添加一个类装饰器,就可以设置路由。 直接类或装饰方法。~~@路线(“/”, 调度=[“get”])~~
如果 路由和http方法匹配。
类似烧瓶的布线示例:
@app.make_method_routes() class HelloHandler(BaseHandler): @route(r'/hello/<int:identifier>', dispatch=["get"]) def hello(self, identifier=None): self.write("Hello world! " + str(identifier))
对于Regex路线:
@app.add_route("/test/([0-9]+)*", dispatch={"get" : "test"})
添加直接路由:匹配正则表达式:/test/([0-9+]) 然后调用处理程序类的给定方法。正则表达式组 ([0-9+])将作为第一个要测试的参数(self,index)
使用cerberus模式进行船上模型验证。
所有模型模式都是cerberus模式。所以这很简单。 ~~model.validate()=>;执行cerberus验证器~~
最后:一个超级简单的工作流程。快速开始,所有的基础知识 板和易于扩展:生成方法(但不嘈杂)
- 生成应用程序脚本
- 生成模型脚本(您可能希望存储一些数据)
- 可选地生成_migrations脚本(仅用于SQL数据库)
- 生成处理程序(aka controllers以定义逻辑和api)
- 启动服务器(python server.py)完成
愿景:
If you want start to develop your web-application and focus on the App, instead of the frameworks, you are in the right place. PythonOnWheels feels right if you do not recognize that you use it.