Skip to content

Commit

Permalink
update python example
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jul 26, 2020
1 parent 8dc04e4 commit 77988bd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 45 deletions.
39 changes: 4 additions & 35 deletions python/index.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,5 @@
# -*- coding: utf-8 -*-

from hi import hi,template
import os

app =hi()

@app.route(r'^/(test|hello)/?$',['GET'])
def hello_world(req,res,param):
res.header('Content-Type','text/plain;charset=utf-8')
res.content('hello,world')
res.status(200)

@app.route(r"^/client/?$",['GET','POST'])
def client(req,res,param):
res.content('{}<br>{}<br>{}<br>{}<br>{}'.format(req.client(),req.method(),req.uri(),req.user_agent(),req.param()))
res.status(200)

@app.route(r"^/hello/(?P<who>\w+)?$",['GET'])
def hello(req,res,param):
res.content('{}={}'.format('who',param['who']))
res.status(200)

@app.route(r'^/template/(?P<name>\w+)/(?P<age>\d+)/?$',['GET'])
def tpl(req,res,param):
param['title']='测试 jinja2 template'
tpl_engine = template(os.path.join(os.getcwd(),'python/templates'))
res.content(tpl_engine.file_render('b.html',param))
res.status(200)


if __name__ == '__main__':
app.run(hi_req,hi_res)


# see https://github.com/webcpp/pyexample

hi_res.header('Content-Type', 'text/plain;charset=UTF-8')
hi_res.content('hello,world')
hi_res.status(200)
4 changes: 0 additions & 4 deletions python/templates/a.html

This file was deleted.

6 changes: 0 additions & 6 deletions python/templates/b.html

This file was deleted.

0 comments on commit 77988bd

Please sign in to comment.