什么是大型蟒蛇龙卷风项目的最佳结构?

car*_*ted 4 python structure tornado large-scale

我正在使用以龙卷风为核心的mongodb数据库后端.我目前只有我的主文件中有一堆处理程序.它是一个多用户webapp,在用户之间有链接,也就是"朋友"系统.

My current structure is:
    templates/
    static/
    main.py (contains all handlers)
    user_actions.py
    auth_actions.py
    .
    .
    .
    bar_actions.py
Run Code Online (Sandbox Code Playgroud)

大多数处理程序对应于动作文件.例如,友元请求处理程序对应于user_actions.py中的函数,该函数接受数据库和userids作为参数.我觉得这不是这么大项目的最佳布局.我是否应该有某种类型的模型文件包含当前用户的模型,或者这只是多余的.我目前正在将当前用户存储为cookie中的字典.

dm0*_*514 7

如果您有许多处理程序,每个处理程序都有代码,您可以将它们分解为自己的文件并将它们handlers放在应用程序内的目录中.

Tornado没有强制执行结构,因此我会查看示例龙卷风项目和github上的任何开源龙卷风项目,以了解其他人的结构.

我只做了1个龙卷风项目,但我在网上找到的例子使用了我上面概述的惯例:

??? app.py
??? common
?   ??? __init__.py
?   ??? utils.py
??? custom_settings.py
??? handlers
?   ??? user_handler.py
?   ??? auth_handler.py
?   ??? __init__.py
??? __init__.py
??? requirements.txt
??? scripts
??? supervisord.conf
??? tests
    ??? __init__.py
    ??? test_common.py
    ??? test_handlers.py
Run Code Online (Sandbox Code Playgroud)