python - Flask使用 Blueprint 出現(xiàn)ImportError: cannot import name ’Blueprint’?
問題描述
最近新學(xué) Flask,想嘗試使用藍(lán)圖模塊化應(yīng)用。但甚至在運(yùn)行簡易 demo 時就出錯。
這個簡易應(yīng)用有兩個文件:app.py
from flask import Flaskapp = Flask(__name__)from calendar import calendarapp.register_blueprint(calendar, url_prefix=’/auth’)@app.route(’/’)def hello_world(): return ’Hello World!’if __name__ == ’__main__’: app.run(port=8023)
calendar.py
from flask import Blueprint calendar = Blueprint(’calendar’, __name__) @calendar.route(’/’) def test():return ’yes’
運(yùn)行時出現(xiàn)錯誤:
Traceback (most recent call last): File '/Users/vencent/.pyenv/versions/ec-env-3.6.0/lib/python3.6/site-packages/werkzeug/http.py', line 22, in <module> from email.utils import parsedate_tz File '/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/email/utils.py', line 33, in <module> from email._parseaddr import quote File '/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/email/_parseaddr.py', line 16, in <module> import time, calendar File '/Users/vencent/PycharmProjects/untitled1/calendar.py', line 1, in <module> from flask import BlueprintImportError: cannot import name ’Blueprint’During handling of the above exception, another exception occurred:Traceback (most recent call last): File '/Users/vencent/PycharmProjects/untitled1/untitled1.py', line 1, in <module> from flask import Flask File '/Users/vencent/.pyenv/versions/ec-env-3.6.0/lib/python3.6/site-packages/flask/__init__.py', line 17, in <module> from werkzeug.exceptions import abort File '/Users/vencent/.pyenv/versions/ec-env-3.6.0/lib/python3.6/site-packages/werkzeug/__init__.py', line 151, in <module> __import__(’werkzeug.exceptions’) File '/Users/vencent/.pyenv/versions/ec-env-3.6.0/lib/python3.6/site-packages/werkzeug/exceptions.py', line 71, in <module> from werkzeug.wrappers import Response File '/Users/vencent/.pyenv/versions/ec-env-3.6.0/lib/python3.6/site-packages/werkzeug/wrappers.py', line 26, in <module> from werkzeug.http import HTTP_STATUS_CODES, File '/Users/vencent/.pyenv/versions/ec-env-3.6.0/lib/python3.6/site-packages/werkzeug/http.py', line 24, in <module> from email.Utils import parsedate_tzModuleNotFoundError: No module named ’email.Utils’
之前嘗試把已有的項目用 Blueprint 模塊化也是這樣的提示,當(dāng)時以為是跟其他代碼有沖突。今天試了一下發(fā)現(xiàn)這個 demo 都運(yùn)行不了...
問題解答
回答1:werkzeug 的版本不兼容 python 3.6? 更新一下 werkzeug 試試。
相關(guān)文章:
1. windows誤人子弟啊2. php傳對應(yīng)的id值為什么傳不了啊有木有大神會的看我下方截圖3. 如何用筆記本上的apache做微信開發(fā)的服務(wù)器4. python - linux 下用wsgifunc 運(yùn)行web.py該如何修改代碼5. 關(guān)于mysql聯(lián)合查詢一對多的顯示結(jié)果問題6. 實(shí)現(xiàn)bing搜索工具urlAPI提交7. 冒昧問一下,我這php代碼哪里出錯了???8. mysql優(yōu)化 - MySQL如何為配置表建立索引?9. MySQL主鍵沖突時的更新操作和替換操作在功能上有什么差別(如圖)10. 數(shù)據(jù)庫 - Mysql的存儲過程真的是個坑!求助下面的存儲過程哪里錯啦,實(shí)在是找不到哪里的問題了。
