模板main.py开发
定义模板全局变量 config、render
#coding: utf-8
import web
urls = (
'/', 'index',
'/renderTest', 'Test',
'/TodoLists', 'todo.TD',
'/TodoLists/(\w+)', 'todo.TD_Simple',
)
render = web.template.render('templates')
class Test:
def GET(self):
return render.showRender('hello world')
from pymongo import MongoClient
# Making a Connection with MongoClient
client = MongoClient('localhost', 27017)
# Getting a Database
db = client['todo-db']
# Getting a Collection
collection = db['TodoLists']
class index:
def GET(self):
return "Hello, world!"
config = web.storage(
email='[email protected]',
site_name = '任务跟踪',
site_desc = '',
static = '/static',
)
web.template.Template.globals['config'] = config
web.template.Template.globals['render'] = render
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()