将路由拆分为多个文件klein python

问题描述

我有一个奇怪的要求。我想将单个main.py下的路由拆分为多个文件我有一个解决方案,我在'/'路由下返回file_name.app.resource()来从file_name.py文件调用路由。出于显而易见的原因,我无法在“ /”路由下返回多个app.resources()(方法无法返回多个值)。 只要添加一条子路线,便有可能。我可以在没有任何子路由的情况下实现此目标吗? 目前,这就是我所拥有的:

from klein import Klein  #in main.py
from twisted.web.static import File

from routes import blueprint,main    # this module holds the other Klein app

app = Klein()


@app.route('/branch',branch=True)
def branchOff2(request):
    return routes_file.app.resource()



from klein import Klein   # in routes_file.py
app = Klein()

@app.route('/hello')
def index(request):
    return 'Hello from the subroutes main example'

with app.subroute('/blue') as sub:
    @sub.route('/first')
    def first(request):
        return 'first'

    @sub.route('/second')
    def second(request):
        return 'second'

    @sub.route('/third')
    def third(request):
        return 'third'
#
# if __name__ == '__main__':
#     app.run(host='localhost',port=8083)

任何帮助将不胜感激。谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)