Guoliangcai
Guoliangcai

Reputation: 57

How to organize my flask project properly?

I'm writing my blog project by flask and sqlalchemy, but I don't know how to organize it.Here is is the file tree: enter image description here the admin and main are two blueprint, I create my app in the blog's __init__.py. But where should I create my models and how to use it correctly?enter image description here

Can I create an engine instance and make it global? So that everytime I need to connect to database, I just need to make a new session and bind this engine? Or should I establish new connection and engine for every request?

Upvotes: 1

Views: 702

Answers (1)

mlyy
mlyy

Reputation: 66

I personally prefer the global instance method for two reasons. First it can reduce the handshake cost since it's a long-live connection. Second, it can easily transform into a connection pool.

Upvotes: 1

Related Questions