kpages- 以api 为中心的高性能web 框架

网友投稿 806 2022-10-26

kpages- 以api 为中心的高性能web 框架

kpages- 以api 为中心的高性能web 框架

kpages

kpages is mini helper for tornado,Contains the address routingmanagement,tornado and app config management, mongodb, redis connectionmanagement and other functions; these supports can help you quickly build aweb application.

Case

Migrant

[](https://github.com/comger/kpages#how-to-create-kpages-project-version--

063dev)How to create kpages project (version >= 0.6.3.dev)

1. input command: kpages_init.py projectname # projectname: you project name, default is kpages_project2. set you RequestHandler action dir

[](https://github.com/comger/kpages#how-to-start-kpages-web-

application)How to start kpages web application

python apprun.py or ./apprun.pyParams config=CONFIG set config for server port=PORT set http port for server debug Debug mode. ndebug No Debug mode.

How to start

kpages mq

python service.py 或 ./service.pyParams config=CONFIG set config for server port=PORT set http port for server debug Debug mode. ndebug No Debug mode. channel set channel for redis mq

How to router

restful/index.py(add @url to class , kpages will route url to this handler)

from kpages import url@url(r'/',0)@url(r'/home',2)class HomeHandler(RequestHandler): def get(self): self.write('hello word')

setting.py

#config for tornado and you app, use __conf__.xxxx to get you config valueACTION_DIR = 'restful'DEBUG = TruePORT= 8989

How to use

kpages app

from kpages import rundef callback(app): passif __name__ == '__main__': run(callback)

How

to use mongo and redis context?

from kpages import get_context, LogicContext,mongo_convwith LogicContext(): db = get_context().get_mongo() cache = get_context().get_redis() lst = list(db['table'].find().limit(10)) lst = mongo_conv(lst)

[](https://github.com/comger/kpages#how-to-use-context-in-hander-with-

session-)How to use context in hander( with session )?

from kpages import ContextHandler@url(r'/context/demo')class DemoHandler(ContextHandler,tornado.web.RequestHandler): def get(self): db = get_context().get_mongo('dbname') val = self.session(key) self.session(key,val)

test command

run_test(test_city.DemoCase.testprint) :test testprint methodrun_test(test_city.DemoCase) :test methods in DemoCase classrun_test(test_city) :test methods in test_city.pyrun_test(all ) :test methods in app's __conf__.UTEST_DIR

pro command

pro_test(test_city.DemoCase.testprint) :profile testprint methodpro_test(test_city.DemoCase) :profile methods in DemoCase classpro_test(test_city) :profile methods in test_city.pypro_test(all) :profile methods in app's __conf__.UTEST_DIR

[](https://github.com/comger/kpages#how-to-use--uimodule-and-uimethod-in-

kpages)How to use uimodule and uimethod in kpages

1. kpages can auto find Ui_Module's subclass in ACTION_DIR2. you can use {% module dir_modulename_classname() %} to call Ui ModuleDemo Code Class Demo(tornado.web.UIModule): def render(self,name): return self.render('

Hello world:{0}

'.format(name))Template code {% module Demo('kpages') %}3. @reg_ui_method in ACTION_DIR's files, to apply Ui methodsDemo code @reg_ui_method(name='testmethod',intro='demo for ui method') def add(self,a,b): return a+bTemplate code {{ add(3,4) }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:ByteArrayOutputStream 类源码分析
下一篇:并发编程 -- 原子操作原理
相关文章

 发表评论

暂时没有评论,来抢沙发吧~