Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

kpages is api-centric web application framework for the Tornado and Mongodb

Project Description
#kpages

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

## Case
* [Migrant](https://github.com/comger/migrant)


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

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

## How to start kpages web application
```
python apprun.py or ./apprun.py
Params
config=CONFIG set config for server
port=PORT set http port for server
debug Debug mode.
ndebug No Debug mode.



you can run script kpages_web.py in you app root dir (version >= 0.8.0.dev)
```

## How to start kpages mq
```
python service.py 或 ./service.py
Params
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

you can run script kpages_service.py in you app root dir (version >= 0.8.0.dev)
```


##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 value
ACTION_DIR = 'restful'
DEBUG = True
PORT= 8989
```

## How to use kpages app

```
from kpages import run

def callback(app):
pass

if __name__ == '__main__':
run(callback)
```

## How to use mongo and redis context?
```
from kpages import get_context, LogicContext,mongo_conv

with LogicContext():
db = get_context().get_mongo()
cache = get_context().get_redis()
lst = list(db['table'].find().limit(10))
lst = mongo_conv(lst)

```

## 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)
```

## How to use model
```
class Demo(Model):
_name = 'collection_name'
_fields = dict(
name = CharField(required=True),
sex = IntField(label='sex',initial=1,required=True),
pwd = CharField(label='password')
)


m = Demo()
m = Demo(dbname)
master = ModelMaster()
# set dbname for Master's model
master = ModelMaster(dbname)

# get attr, this method can auto create temp model; set collection name as modelname_model
m = master.modelname

# call get attr
m = master(modelname)

# call get attr and temp dbname
m = master(modelname,dbname)

_id = m.insert(data)
m.update(_id, c = 'acd')
obj = m.info(_id)
m.remove(_id)
cursor = m.page(page=1,size=10,**condition)

#parse requesthandler arguments to model
data = m.fetch_data(requesthandler)
data is like {'name':'youname','sex':1,'pwd':'xdssss'}
```

## test command
```
run_test(test_city.DemoCase.testprint) :test testprint method
run_test(test_city.DemoCase) :test methods in DemoCase class
run_test(test_city) :test methods in test_city.py
run_test(all ) :test methods in app's __conf__.UTEST_DIR
```

## pro command
```
pro_test(test_city.DemoCase.testprint) :profile testprint method
pro_test(test_city.DemoCase) :profile methods in DemoCase class
pro_test(test_city) :profile methods in test_city.py
pro_test(all) :profile methods in app's __conf__.UTEST_DIR

```

## How to use uimodule and uimethod in kpages
```
1. kpages can auto find Ui_Module's subclass in ACTION_DIR
2. you can use {% module dir_modulename_classname() %} to call Ui Module
Demo Code
Class Demo(tornado.web.UIModule):
def render(self,name):
return self.render('<h1>Hello world:{0}</h1>'.format(name))

Template code
{% module Demo('kpages') %}


3. @reg_ui_method in ACTION_DIR's files, to apply Ui methods
Demo code

@reg_ui_method(name='testmethod',intro='demo for ui method')
def add(self,a,b):
return a+b

Template code
{{ add(3,4) }}

```


Release History

Release History

This version
History Node

1.3.5.dev0

History Node

1.3.4.dev0

History Node

1.3.3.dev0

History Node

1.3.2.dev0

History Node

1.3.1.dev0

History Node

1.2.9.dev

History Node

1.2.8.dev

History Node

1.2.7.dev

History Node

1.2.6.dev0

History Node

1.2.5.dev0

History Node

1.2.5.dev

History Node

1.2.4.dev

History Node

1.2.4.dev0

History Node

1.2.3.dev

History Node

1.2.2.dev

History Node

1.2.1.dev

History Node

1.2.0.dev

History Node

1.1.9.dev

History Node

1.1.8.dev

History Node

1.1.7.dev

History Node

1.1.6.dev

History Node

1.1.5.dev

History Node

1.1.4.dev

History Node

1.1.3.dev

History Node

1.1.2.dev

History Node

1.1.1.dev

History Node

1.1.0.dev

History Node

1.0.9.dev

History Node

1.0.8.dev

History Node

1.0.7.dev

History Node

1.0.6.dev

History Node

1.0.5.dev

History Node

1.0.4.dev

History Node

1.0.3.dev

History Node

1.0.2.dev

History Node

1.0.1.dev

History Node

1.0.0.dev

History Node

0.9.8.dev

History Node

0.9.7.dev

History Node

0.9.6.dev

History Node

0.9.5.dev

History Node

0.9.4.dev

History Node

0.9.3.dev

History Node

0.9.2.dev

History Node

0.9.1.dev

History Node

0.9.0.dev

History Node

0.8.9.dev

History Node

0.8.8.dev

History Node

0.8.7.dev

History Node

0.8.6.dev

History Node

0.8.5.dev

History Node

0.8.3.dev

History Node

0.8.2.dev

History Node

0.8.1.dev

History Node

0.8.0.dev

History Node

0.7.9.dev

History Node

0.7.8.dev

History Node

0.7.7.dev

History Node

0.7.6.dev

History Node

0.7.5.dev

History Node

0.7.4.dev

History Node

0.7.3.dev

History Node

0.7.2.dev

History Node

0.7.1.dev

History Node

0.7.0.dev

History Node

0.6.9.dev

History Node

0.6.8.dev

History Node

0.6.7.dev

History Node

0.6.6.dev

History Node

0.6.5.dev

History Node

0.6.4.dev

History Node

0.6.3.dev

History Node

0.6.2.dev

History Node

0.5.9.dev

History Node

0.5.8.dev

History Node

0.5.7.dev

History Node

0.5.6.dev

History Node

0.5.5.dev

History Node

0.5.4.dev

History Node

0.5.3.dev

History Node

0.5.2.dev

History Node

0.5.1.dev

History Node

0.4.3.dev

History Node

0.4.2.dev

History Node

0.4.1.dev

History Node

0.3.1.dev

History Node

0.3.dev

History Node

0.2.dev

History Node

0.1.dev

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
kpages-1.3.5.dev0-py2.7.egg (125.1 kB) Copy SHA256 Checksum SHA256 2.7 Egg Jun 6, 2017
kpages-1.3.5.dev0.tar.gz (81.8 kB) Copy SHA256 Checksum SHA256 Source Jun 6, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting