Lion
Lion

Reputation: 11

AttributeError: module 'werkzeug.wrappers.request' has no attribute 'method'

I get this error when I try to open the sign-up page. Also "if request.method == 'POST':" part of code is highlighted.

from typing import Text
from flask import Blueprint, render_template, request, flash
from werkzeug.wrappers import request

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')

        
    return render_template("sign_up.html")

Upvotes: 0

Views: 1015

Answers (2)

Lucas
Lucas

Reputation: 91

Just to complement Leonard's answer and for anyone at the same situation.

It turns out VS Code autoimported request from werkzeug.wrappers instead of flask when I first used it. Removing that import line solved the problem for me.

Upvotes: 0

Leonard
Leonard

Reputation: 833

The problem is that you're importing a request module two times (one time from flask, the other time from werkzeug). One workaround is to rename the second import, i.e.,

from werkzeug.wrappers import request as werkzeug_request

Then, whenever you need that module, use werkzeug_request.

But you probably don't even want that import, so I would suggest to remove the import from werkzeug and get the form data as follows:

email = request.form['email']

Upvotes: 3

Related Questions