Flask ImportError:无法导入名称'app'

时间:2016-11-06 04:38:29

标签: python flask

我是新手,试图学习蓝图,但我遇到了麻烦。我的文件结构是这样的:

documents\flask(directory of my flask projects)
               \blueprint(my current project)
                    \site(where the modules sits)
                         \api
                             __init__.py
                             routes.py
                         \site
                             __init.py
                             routes.py 
                    __init__.py
               run.py

网站/ routes.py

from flask import Blueprint

mod_site = Blueprint('site', __name__)

@mod_site.route('/')
def main():
    return '<h1>You are on the homepage!</h1>'

API / routes.py

from flask import Blueprint

mod_api = Blueprint('api', __name__)

@mod_api.route('/getdata')
def getData():
    return '{"result":"You are in the API!"}'

网站(主文件夹)/ init .py

from flask import flask

app = Flask(__name__)

from site.api.routes import mod_api as api_module
from site.site.routes import mod_site as site_module

app.register_blueprint(site_module)
app.register_blueprint(api_module, url_prefix='/api')

run.py

from site import app

app.run(debug=True)

运行时出现此错误:

Traceback (most recent call last):
 File "run.py", line 1, in <module>
   from site import app 
ImportError: cannot import name 'app'

0 个答案:

没有答案