4

I'm using a mongodb database backend with tornado as my core. I currently just have my main file with a bunch of handlers in it. It's a multiuser webapp with links between users, aka a "friend" system.

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

Most of the handlers correspond to actions file. For example a friend request handler corresponds to function in user_actions.py that accepts the database and userids as parameters. I feel like this isn't the best layout for such a large project. Should I have some type of models file containing models of the current user or is this just excess. I'm currently storing the current user as a dictionary, in a cookie.

carboncomputed
  • 1,630
  • 3
  • 20
  • 42

1 Answers1

8

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
smholloway
  • 589
  • 7
  • 14
dm03514
  • 54,664
  • 18
  • 108
  • 145