资讯专栏INFORMATION COLUMN

xweb: 一款无依赖的python web框架(低于500行代码)

waterc / 2583人阅读

摘要:地址简介用极少的代码实现一款框架,目标是用低于行的代码实现的核心功能,框架基于以上开发特点安装路由请求相应中间件欢迎或者地址

github地址: https://github.com/gaojiuli/xweb

简介

用极少的代码实现一款web框架,目标是用低于1000行的代码实现flask的核心功能,xweb框架基于python3.5以上开发

特点

few code

do more

no dependencies

安装

pip install xweb

hello world
from xweb.application import XWeb

app = XWeb()


@app.route("/")
def hello():
    return "hello world!"


app.listen(3000)
路由
from xweb.application import XWeb

app = XWeb()


@app.route("/:name/")
def call_my_name(name):
    return "hi {}!".format(name)


app.listen(3000)
请求
from xweb.globals import request

request.path
request.query_string
request.query
request.files
request.forms
request.json
request.ip
request.hostname
request.headers
相应
from xweb.globals import response

response.headers
response.status
response.body
中间件
from xweb.application import XWeb

app = XWeb()

@app.middleware("request")
def print_on_request1():
    print("I print when a request is received by the server1")


@app.middleware("request")
def print_on_request2():
    print("I print when a request is received by the server2")


@app.middleware("response")
def print_on_response1():
    print("I print when a response is returned by the server1")


@app.middleware("response")
def print_on_response2():
    print("I print when a response is returned by the server2")

@app.route("/:name/")
def call_my_name(name):
    return "hi {}!".format(name)


app.listen(3000)
TODO

more http status code

some necessary middleware

enough test code

support blueprint

a cool logo

欢迎star或者fork

github地址: xweb

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/38484.html

相关文章

  • xweb: 款无依赖python web框架(低于500代码)

    摘要:地址简介用极少的代码实现一款框架,目标是用低于行的代码实现的核心功能,框架基于以上开发特点安装路由请求相应中间件欢迎或者地址 github地址: https://github.com/gaojiuli/xweb 简介 用极少的代码实现一款web框架,目标是用低于1000行的代码实现flask的核心功能,xweb框架基于python3.5以上开发 特点 few code do more...

    TwIStOy 评论0 收藏0
  • xweb: 后端开发应该是简洁, 禅意

    摘要:简介项目地址众所周知如今的后端开发主要是负责接口的开发而前后端分离又是当下最流行的如果使用技术栈通常情况下我们会选择全套或者他们的模板引擎功能在当下的后端开发中是基本不用的同时由于它们开始的时候是基于写的造成了现在代码中充斥着大量丑陋的兼容 简介 showImg(https://segmentfault.com/img/remote/1460000008633918?w=280&h=1...

    lindroid 评论0 收藏0
  • 后端文章 - 收藏集 - 掘金

    摘要:为什么我会说它们是一样的简单思考一下我的后端书架后端掘金我的后端书架月前本书架主要针对后端开发与架构。一方案调研版本选择当前主流版本是和应用的后台运行配置后端掘金酱油一篇,整理一下关于后台运行的一些配置方式。 分享 50 个完整的 React Native 项目 - 掘金本文为 Marno 原创,转载必须保留出处! 公众号 aMarno,关注后回复 RN 加入交流群 简书专题《 Rea...

    CntChen 评论0 收藏0
  • JavaScript开发工具大全

    摘要:发布于之后,采用了完全不同的方式,使用函数定义任务。它允许开发者使用它们的补丁和更新来修复这些安全漏洞。提供了工具用于扫描依赖来监测漏洞。是一个开源诊断工具,用于和应用。是和开发的一款新的包管理工具。与相比,它解决了安全性能以及一致性问题。 译者按: 最全的JavaScript开发工具列表,总有一款适合你! 原文: THE ULTIMATE LIST OF JAVASCRIPT TOO...

    nifhlheimr 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<