我用极少的代码了实现一款 web 框架,目标是用低于 1000 行的代码实现 flask 的核心功能, xweb 框架基于 python3.5 以上开发,实在是居家旅行良品.
github 地址:https://github.com/gaojiuli/xweb
我的目标是用最少的代码实现符合现状的 web 框架,欢迎同样有兴趣的同学一起参与进来
基于3.5开发
pip install xweb
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)
我的目标是用最少的代码实现符合现状的 web 框架,欢迎同样有兴趣的同学一起参与进来
github 地址:https://github.com/gaojiuli/xweb
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.