我的项目结构如下:
apps
app1
__init__.py
views.py
app2
__init__.py
views.py
__init__.py
main.py
routes.py
如何按应用拆分路线,将它们放入自己的应用中,并将它们包含在" global"像django这样的路由器包含吗?
答案 0 :(得分:3)
您可以这样做:
在apps \ app1 \ views.py
中new
在apps \ app2 \ views.py
中def a():
count1=[0]
count2=0
def b():
nonlocal count2
count1[0]=count1[0]+1
count2=count2+1
print (count1,count2)
b()
a()
在routes.py
来自app1.views的将路由导入为app1_routes 从app2.views导入路线为app2_routes
from aiohttp import web
async def route_path_def(request):
return web.Response(body=b'Some response')
routes = (
{'GET', '/route_path', route_path_def, 'route_path_name'}
)
在main.py
from aiohttp import web
async def another_route_path_def(request):
return web.Response(body=b'Some response')
routes = (
{'GET', '/another_route_path', another_route_path_def, 'another_route_path_name'}
)
为我工作得很好:)。