《Flask Web开发》学习笔记之bug--(7)【ImportError: cannot import name 'db'】

工程结构:

$ pwd;ls
/home/henry/dev/Flask_Web_Python_Henry/flask_henry
app        manage.py   __pycache__       tests  venv_henry_0717
config.py  migrations  requirements.txt  venv

$ pwd;ls
/home/henry/dev/Flask_Web_Python_Henry/flask_henry/app
email.py   main       __pycache__  templates
_init_.py  models.py  static

报错信息:



$ python3 manage.py shell
Traceback (most recent call last):
  File "manage.py", line 3, in 
    from app.models import User, Role
  File "/home/henry/dev/Flask_Web_Python_Henry/flask_henry/app/models.py", line 3, in 
    from . import db
ImportError: cannot import name 'db'

没有在Google或者Stack Overflow找到合适的解决办法,对比原书作者的代码,发现问题出在_init_.py的文件名,应当为__init__.py。

一点感慨:Python的基础很重要,在《Python 学习手册》中,大概是“模块、包”的章节,有提到,【】模块】目录下面,应当有【__init__.py】文件。

你可能感兴趣的:(Flask,Python的坑,Python,bug,debug)