You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

打开注册页面时触发AttributeError:module 'werkzeug.wrappers.request' has no attribute 'method'错误的技术求助

Fixing the 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

  1. Remove the unnecessary Werkzeug import: Delete this line entirely:
    from werkzeug.wrappers import request
    
  2. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 07:47:31