0

プロジェクト用のログインサインアップ Web ページの作成を開始しています。そのために「wtforms」を使用したいのですが、flask-bootstrap ライブラリを使用しないと例が見つかりません。フラスコブートストラップなしで wtform を使用できますか?

いくつかの実験を行いましたが、うまくいかないようです。

これは私のコードです: HTML:

<div class="login-form">
        <form action="/registration" method="POST">
            <h2 class="text-center">Registrazione</h2>
            <div class="form-group has-error">
                <input type="text" class="form-control" name="nome" placeholder="Nome" required="required">
            </div>
            <div class="form-group has-error">
                <input type="text" class="form-control" name="cognome" placeholder="Cognome" required="required">
            </div>
            <div class="form-group">
                <input type="email" class="form-control" name="email" placeholder="E-mail" required="required">
            </div>
            <div class="form-group">
                <input type="password" class="form-control" name="password" placeholder="Password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="la password deve contenere almeno un numero, una lettera maiuscola, una minuscola e deve essere almeno di 8 carateri" required="required">
            </div>
            <div class="form-group">
                <input type="password" class="form-control" name="confermaPsw" placeholder="Conferma password"  pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="la password deve contenere almeno un numero, una lettera maiuscola, una minuscola e deve essere almeno di 8 carateri" required="required">
            </div>
            <div class="form-group">
                <select class="form-control" name="ruolo" id="sel1" required="required">
                   <option>SW</option>
                   <option>PM</option>
                   <option>PE</option>
                </select>
            </div>
            <div class="form-group">
                <button type="submit" class="btn btn-primary btn-lg btn-block">Registrati</button>
            </div>
        </form>

パイソン:

class RegisterForm(FlaskForm):
    name = StringField('name', validators=[InputRequired(), Length(min=4, max=15)])
    surname = StringField('surname', validators=[InputRequired(), Length(min=4, max=15)])
    email = StringField('email', validators=[InputRequired(), Length(max=50)])
    password = PasswordField('password', validators=[InputRequired(), Length(min=8, max=80)])
    ruolo = StringField('urole', validators=[InputRequired()])

@app.route('/registration', methods=['POST', 'GET'])
def registration():
    # se tutti gli input rispettano i prerequisiti di validazione, aggiungi utente
    form = RegisterForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            hashed_password = generate_password_hash(form.password.data, method='sha256')
            new_user = User(name=form.nome.data, surname=form.cognome.data, email=form.email.data, password=hashed_password, urole=form.ruolo.data)
            db.session.add(new_user)
            db.session.commit()

            return '<h1>New user has been created!</h1>'
        return '<h1>post send but no validate!</h1>'

    return render_template("registration.html", form=form)


EDIT: I need to have the same formatting I had before using WTForms
 
4

1 に答える 1