当前位置: 首页>>代码示例>>Python>>正文


Python WSGIApplication.add_module方法代码示例

本文整理汇总了Python中transwarp.web.WSGIApplication.add_module方法的典型用法代码示例。如果您正苦于以下问题:Python WSGIApplication.add_module方法的具体用法?Python WSGIApplication.add_module怎么用?Python WSGIApplication.add_module使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在transwarp.web.WSGIApplication的用法示例。


在下文中一共展示了WSGIApplication.add_module方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

# 需要导入模块: from transwarp.web import WSGIApplication [as 别名]
# 或者: from transwarp.web.WSGIApplication import add_module [as 别名]
    def __call__(self, path, model):
        return "<!-- override this method to render template -->"


class Jinja2TemplateEngine(TemplateEngine):
    def __init__(self, templ_dir, **kw):
        from jinja2 import Environment, FileSystemLoader

        if not "autoescape" in kw:
            kw["autoescape"] = True
        self._env = Environment(loader=FileSystemLoader(templ_dir), **kw)

    def add_filter(self, name, fn_filter):
        self._env.filters[name] = fn_filter

    def __call__(self, path, model):
        return self._env.get_template(path).render(**model).encode("utf-8")


# init wsgi app:
wsgi = WSGIApplication(os.path.dirname(os.path.abspath(__file__)))
template_engine = Jinja2TemplateEngine(os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates"))
wsgi.template_engine = template_engine
wsgi.add_module(urls)  # 把url中的路径-函数,打包成映射关系,路径:route,route是从原python函数


if __name__ == "__main__":
    wsgi.run(9000, host="0.0.0.0")  # 自己运行,使用内置的web服务器
else:
    application = wsgi.get_wsgi_application()  # 传递给其他模块
开发者ID:hxcai,项目名称:server-1,代码行数:32,代码来源:wsgiapp.py

示例2: WSGIApplication

# 需要导入模块: from transwarp.web import WSGIApplication [as 别名]
# 或者: from transwarp.web.WSGIApplication import add_module [as 别名]
A WSGI application entry.
'''

import logging; logging.basicConfig(level=logging.INFO)

import os

from transwarp import db
from transwarp.web import WSGIApplication, Jinja2TemplateEngine

from config import configs

# init db:
db.create_engine(**configs.db)

# init wsgi app:
wsgi = WSGIApplication(os.path.dirname(os.path.abspath(__file__)))

template_engine = Jinja2TemplateEngine(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates'))

wsgi.template_engine = template_engine

import urls

wsgi.add_interceptor(urls.user_interceptor)
wsgi.add_interceptor(urls.manage_interceptor)
wsgi.add_module(urls)

if __name__ == '__main__':
    wsgi.run(8000)
开发者ID:Spacebody,项目名称:ProfStudSystem,代码行数:32,代码来源:wsgiapp.py

示例3: WSGIApplication

# 需要导入模块: from transwarp.web import WSGIApplication [as 别名]
# 或者: from transwarp.web.WSGIApplication import add_module [as 别名]
    if delta < 604800:
        return u'%s天前' % (delta // 86400)
    dt = datetime.datetime.fromtimestamp(t)
    return u'%s年%s月%s日' % (dt.year, dt.month, dt.day)


# 初始化数据库
db.create_engine(**configs.db)

# init wsgi app
wsgi = WSGIApplication(os.path.dirname(os.path.abspath(__file__)))

template_engine = Jinja2TemplateEngine(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates'))
template_engine.add_filter('datetime', datetime_filter)

wsgi.template_engine = template_engine

import urls, api_urls
wsgi.add_interceptor(urls.user_interceptor)
wsgi.add_interceptor(urls.manage_interceptor)
wsgi.add_module(urls)
wsgi.add_module(api_urls)

if __name__ == '__main__':
    wsgi.run(9000)
else:
    application = wsgi.get_wsgi_application()



开发者ID:edwingoo,项目名称:mywebapp,代码行数:29,代码来源:wsgiapp.py


注:本文中的transwarp.web.WSGIApplication.add_module方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。