久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

python - Flask使用 Blueprint 出現ImportError: cannot import name ’Blueprint’?

瀏覽:122日期:2022-07-16 09:52:28

問題描述

最近新學 Flask,想嘗試使用藍圖模塊化應用。但甚至在運行簡易 demo 時就出錯。

這個簡易應用有兩個文件: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’

運行時出現錯誤:

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 模塊化也是這樣的提示,當時以為是跟其他代碼有沖突。今天試了一下發現這個 demo 都運行不了...

問題解答

回答1:

werkzeug 的版本不兼容 python 3.6? 更新一下 werkzeug 試試。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 新竹县| 铅山县| 保山市| 防城港市| 赫章县| 高邑县| 千阳县| 南康市| 郧西县| 平和县| 固镇县| 呼玛县| 麦盖提县| 万州区| 宿州市| 崇义县| 三明市| 沙湾县| 安吉县| 普兰店市| 福建省| 盐津县| 大庆市| 泰来县| 谷城县| 金乡县| 辉南县| 宜川县| 神农架林区| 宝坻区| 曲麻莱县| 巴林右旗| 炎陵县| 上饶市| 华宁县| 台南市| 伊宁市| 图片| 遵义市| 富民县| 上虞市|