我的代码参考自bluelog,但结构有些差别。
完整错误打印:
(venv) jerryxin@jerryxin-ThinkPad-Edge-E530:~/PycharmProjects/flaskblog$ flask run
- Serving Flask app “.” (lazy loading)
- Environment: development
- Debug mode: on
- Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
- Restarting with stat
- Debugger is active!
- Debugger PIN: 100-198-447
127.0.0.1 - - [22/May/2019 15:46:13] “GET / HTTP/1.1” 500 -
Traceback (most recent call last):
File “/home/jerryxin/PycharmProjects/flaskblog/init.py”, line 2, in
from blueprints.admin import admin_bp
ImportError: No module named ‘blueprints’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/jerryxin/PycharmProjects/flaskblog/venv/lib/python3.5/site-packages/flask/cli.py”, line 325, in call
self._flush_bg_loading_exception()
File “/home/jerryxin/PycharmProjects/flaskblog/venv/lib/python3.5/site-packages/flask/cli.py”, line 313, in _flush_bg_loading_exception
reraise(*exc_info)
File “/home/jerryxin/PycharmProjects/flaskblog/venv/lib/python3.5/site-packages/flask/_compat.py”, line 35, in reraise
raise value
File “/home/jerryxin/PycharmProjects/flaskblog/venv/lib/python3.5/site-packages/flask/cli.py”, line 302, in _load_app
self._load_unlocked()
File “/home/jerryxin/PycharmProjects/flaskblog/venv/lib/python3.5/site-packages/flask/cli.py”, line 317, in _load_unlocked
self._app = rv = self.loader()
File “/home/jerryxin/PycharmProjects/flaskblog/venv/lib/python3.5/site-packages/flask/cli.py”, line 372, in load_app
app = locate_app(self, import_name, name)
File “/home/jerryxin/PycharmProjects/flaskblog/venv/lib/python3.5/site-packages/flask/cli.py”, line 242, in locate_app
‘\n\n{tb}’.format(name=module_name, tb=traceback.format_exc())
flask.cli.NoAppException: While importing “flaskblog”, an ImportError was raised:
Traceback (most recent call last):
File “/home/jerryxin/PycharmProjects/flaskblog/venv/lib/python3.5/site-packages/flask/cli.py”, line 235, in locate_app
import(module_name)
File “/home/jerryxin/PycharmProjects/flaskblog/init.py”, line 2, in
from blueprints.admin import admin_bp
ImportError: No module named ‘blueprints’
127.0.0.1 - - [22/May/2019 15:46:13] “GET /?debugger=yes&cmd=resource&f=style.css HTTP/1.1” 200 -
127.0.0.1 - - [22/May/2019 15:46:13] “GET /?debugger=yes&cmd=resource&f=debugger.js HTTP/1.1” 200 -
127.0.0.1 - - [22/May/2019 15:46:13] “GET /?debugger=yes&cmd=resource&f=jquery.js HTTP/1.1” 200 -
127.0.0.1 - - [22/May/2019 15:46:13] “GET /?debugger=yes&cmd=resource&f=console.png HTTP/1.1” 200 -
目录结构:
├── apis
│ └── v1
├── blueprints
│ ├── admin.py
│ ├── auth.py
│ ├── blog.py
│ └── pycache
├── emails.py
├── extensions.py
├── forms.py
├── init.py
├── models.py
├── Pipfile
├── Pipfile.lock
├── pycache
│ ├── extensions.cpython-35.pyc
│ ├── init.cpython-35.pyc
│ └── setting.cpython-35.pyc
├── README.md
├── setting.py
├── static
│ ├── admin
│ ├── auth
│ └── blog
├── templates
│ ├── 404.html
│ ├── 500.html
│ ├── admin
│ ├── auth
│ └── blog
└── venv
├── bin
├── include
├── lib
├── lib64 -> lib
├── pyvenv.cfg
└── src
报错代码:
from flask import Flask
from blueprints.admin import admin_bp
from blueprints.auth import auth_bp
from blueprints.blog import blog_bp
from setting import config
from extensions import bootstrap, db, moment, ckeditor, mail
from apis.v1 import api_v1
import os
def create_app(config_name=None):
if config_name is None:
config_name = os.getenv(‘FLASK_CONFIG’, ‘development’)
else:
print(‘config_name::::%s’, config_name)
app = Flask(‘flaskblog’)
app.config.from_object(config[config_name])
register_logging(app) # 注册日志处理器
register_extensions(app) # 注册扩展(扩展初始化)
register_blueprints(app) # 注册蓝本
register_commands(app) # 注册自定义shell命令
register_errors(app) # 注册错误处理函数
register_shell_context(app) # 注册shell上下文处理函数
register_template_context(app) # 注册模板上下文处理函数