简体   繁体   中英

For flask how can I set the value for a custom input, but not get placeholder?

For my flask and bootstrap login when I set the value it changes the place holder to <input id= , and a random password. Also, the button text includes <".

错误图片

app.py:

class LoginForm(FlaskForm):
    username = StringField(validators=[InputRequired(), Length(
        min=4, max=20)], render_kw={"placeholder": "Username"})
    
    password = PasswordField (validators=[InputRequired(), Length(
        min=4, max=20)], render_kw={"placeholder": "Password"})

@app.route('/login/', methods=['GET', 'POST'])
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user:
            if bycrypt.check_password_hash(user.password, form.password.data):
                login_user(user)
                print('Logged in')
                return redirect(url_for('sucess'))
    return render_template('login.html', form=form)

login.html

        <form method="POST">
        {{ form.hidden_tag() }}
        <h1 class="h3 mb-3 fw-normal text-center text-white">Please sign in</h1>

        <div class="form-floating">
            <input class="form-control" placeholder="name@example.com" value="{{form.username}}">
            <label for="floatingInput">Email address</label>
        </div>
        <br>
        <div class="form-floating">
            <input type="password" class="form-control" id="floatingPassword" placeholder="Password" value="{{form.password}}">
            <label for="floatingPassword">Password</label>
        </div>
        <br>
        <button class="w-100 btn btn-lg btn-warning" type="submit" value="{{form.submit}}">Sign in</button>
        <p class="mt-5 mb-3 text-muted">&copy; 2017–2021</p>
    </form>

尝试将“ type='text' ”添加到电子邮件输入中

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM