4

我正在使用以龙卷风为核心的 mongodb 数据库后端。我目前只有我的主文件,里面有一堆处理程序。这是一个多用户网络应用程序,用户之间有链接,也就是“朋友”系统。

My current structure is:
    templates/
    static/
    main.py (contains all handlers)
    user_actions.py
    auth_actions.py
    .
    .
    .
    bar_actions.py

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

4

1 回答 1

7

If you have lots of handlers with code for each handler you can break them out into their own files and put them in a handlers directory located inside your app.

Tornado doesn't enforce a structure, so I would look at the sample tornado projects and any open source tornado projects on github to get an idea of other people's structures.

I have only made 1 tornado project but the examples I found online used the convention I outlined above:

├── 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
于 2013-03-14T17:18:47.860 回答