python - Flask使用 Blueprint 出現(xiàn)ImportError: cannot import name ’Blueprint’?
問(wèn)題描述
最近新學(xué) Flask,想嘗試使用藍(lán)圖模塊化應(yīng)用。但甚至在運(yùn)行簡(jiǎn)易 demo 時(shí)就出錯(cuò)。
這個(gè)簡(jiǎn)易應(yīng)用有兩個(gè)文件: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)行時(shí)出現(xiàn)錯(cuò)誤:
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’
之前嘗試把已有的項(xiàng)目用 Blueprint 模塊化也是這樣的提示,當(dāng)時(shí)以為是跟其他代碼有沖突。今天試了一下發(fā)現(xiàn)這個(gè) demo 都運(yùn)行不了...
問(wèn)題解答
回答1:werkzeug 的版本不兼容 python 3.6? 更新一下 werkzeug 試試。
相關(guān)文章:
1. javascript - immutable配合react提升性能?2. javascript - sublime快鍵鍵問(wèn)題3. 配置Apache時(shí),添加對(duì)PHP的支持時(shí)語(yǔ)法錯(cuò)誤4. Apache 已經(jīng)把網(wǎng)站根目錄的改為allow from all了,但是服務(wù)器還是不能訪問(wèn)?5. css - 寫頁(yè)面遇到個(gè)布局問(wèn)題,求大佬們幫解答,在線等,急!~6. phpstudy8.1支持win11系統(tǒng)嗎?7. javascript - nodejs關(guān)于進(jìn)程間發(fā)送句柄的一點(diǎn)疑問(wèn)8. 實(shí)現(xiàn)bing搜索工具urlAPI提交9. vue.js - Vue 如何像Angular.js watch 一樣監(jiān)聽數(shù)據(jù)變化10. javascript - 移動(dòng)端上不能實(shí)現(xiàn)拖拽布局嗎?

網(wǎng)公網(wǎng)安備