I recently learned Flask and want to try using blueprint modular applications. But even when running a simple demo it goes wrong.
This simple application has two files:
app.py
from flask import Flask app = Flask(__name__) from calendar import calendar app.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'
Error occurred while running:
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 from email.utils import parsedate_tz File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/email/utils.py", line 33, in from email._parseaddr import quote File "/Users/vencent/.pyenv/versions/3.6.0/lib/python3.6/email/_parseaddr.py", line 16, in import time, calendar File "/Users/vencent/PycharmProjects/untitled1/calendar.py", line 1, in from flask import Blueprint ImportError: 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 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 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 __import__('werkzeug.exceptions') File "/Users/vencent/.pyenv/versions/ec-env-3.6.0/lib/python3.6/site-packages/werkzeug/exceptions.py", line 71, in 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 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 from email.Utils import parsedate_tz ModuleNotFoundError: No module named 'email.Utils'
I also got the same prompt when I tried to use Blueprint to modularize an existing project. At that time, I thought it was conflicting with other codes. I tried it today and found that the demo couldn't even run...
The version of werkzeug is not compatible with python 3.6? Try updating werkzeug.