Your life will be long.
pip install xweb
- 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/',methods=['GET','POST'])
- def call_my_name(name):
- return 'hi {}!'.format(name)
- @app.post('/post/')
- def post():
- return 'hi post!'
- @app.get('/get/')
- def get():
- return 'hi get!'
- @app.put('/put/')
- def put():
- return 'hi put!'
- @app.patch('/patch/')
- def patch():
- return 'hi patch!'
- @app.delete('/delete/')
- def delete():
- return 'hi delete!'
- app.listen(3000)
- from xweb.globals import request
- request.path
- request.query_string
- request.query
- request.files
- request.forms
- request.json
- request.post
- request.ip
- request.hostname
- request.headers
- request.host
- request.protocol
- request.body
- request.content_type
- request.content_length
- from xweb.globals import response
- response.headers
- response.status
- response.body
- from xweb.application import XWeb
- app = XWeb()
- @app.middleware('request')
- def print_on_request():
- print("I print when a request is received by the server")
- @app.middleware('response')
- def print_on_response():
- print("I print when a response is returned by the server")
- @app.route('/:name/')
- def call_my_name(name):
- return 'hi {}!'.format(name)
- app.listen(3000)
- from xweb.application import XWeb
- from xweb.exception import abort
- from xweb.globals import response
- app = XWeb()
- @app.route('/')
- def hello():
- abort(500)
- return 'OK'
- @app.exception(500)
- def hello():
- response.body = "Something wrong"
- app.listen(3000)
- pip install -r requirement.txt
- pytest
Email:
来源: http://www.tuicool.com/articles/iemEvaA