打开注册页面时触发AttributeError:module 'werkzeug.wrappers.request' has no attribute 'method'错误的技术求助
AttributeError: module 'werkzeug.wrappers.request' has no attribute 'method' in Flask Hey there, let's get this sign-up page error sorted out quickly! The root of your problem is a naming conflict between two request imports in your code.
What's Going Wrong?
You've imported request twice:
- Once from Flask (which is the one you actually need for handling requests in your views)
- Another time directly from
werkzeug.wrappers
Flask's request is a pre-configured, context-aware wrapper around Werkzeug's request implementation. When you import the Werkzeug version alongside it, your code ends up trying to use the raw Werkzeug module instead of Flask's ready-to-use request object—hence the missing method attribute.
The Fix
- Remove the unnecessary Werkzeug import: Delete this line entirely:
from werkzeug.wrappers import request - Keep only the Flask import for
request—it has everything you need to access request methods, form data, etc.
Corrected Full Code
from typing import Text from flask import Blueprint, render_template, request, flash auth = Blueprint('auth', __name__) @auth.route('/login', methods=['GET', 'POST']) def login(): return render_template("login.html", boolean=True) @auth.route('/logout') def logout(): return "<p>logout</p>" @auth.route('/sign-up', methods=['GET', 'POST']) def sign_up(): if request.method == 'POST': email = request.form.get('email') firstName = request.form.get('firstName') password1 = request.form.get('password1') password2 = request.form.get('password2') # You might want to add validation logic here before rendering the template! return render_template("sign_up.html")
Quick Note
In most Flask projects, you never need to directly import request from Werkzeug. Flask's global request object handles all the context magic so you can access request data safely in your view functions.
内容的提问来源于stack exchange,提问作者Lion

