ImportError: cannot import name ‘db‘ from partially initialized module ‘app‘ (most likely due to a c

Run the Flask program to report an error:

ImportError: cannot import name 'db' from partially initialized module 'app' (most likely due to a circular import) (/home/z2q/PycharmProjects/flask_demo3/app/__init__.py)

Insert picture description hereIt is not imported from the package. In fact, it is caused by my not reading the book seriously, but this is just enough to let my own know some problems (from the combination of online and reading, I found the answer, solved the problem, and I was very happy)

The main problem is that the order of the import package is not the same, resulting in the corresponding db not created before the import package

I just started with this code structure, and an error will appear after running

Insert picture description hereIt should be
Insert picture description heresummarized like this : (Because the code is executed in order, when you import blueprints from other modules, you need db, but at this time db has not been generated yet, so an error will be reported that you cannot import the corresponding module from it)

Guess you like

Origin blog.csdn.net/BigData_Mining/article/details/107401291