Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `from flask import Flask, render_template
- from flask_wtf import FlaskForm
- from wtforms import StringField, PasswordField, BooleanField
- from wtforms.validators import InputRequired, Email, length, ValidationError
- app = Flask(__name__)
- app.config['SECRET_KEY'] = 'This is a secret'
- class LoginForm(FlaskForm):
- username = StringField('username', validators=[InputRequired()])
- password = PasswordField('password')
- @app.route('/form', methods=['GET','POST'])
- def form():
- form=LoginForm()
- return render_template('form.html', form=form)
- if __name__== '__main__':
- app.run(debug=True)
- <html>
- <title> MY FORM </title>
- <body>
- <form method="POST" action="{{ url_for('form') }}">
- {{form.csrf_token}}
- {{ form.username.label }}
- {{ form.username }}
- <ul>
- {% for error in form.username.errors %}
- <li style="color: red;">{{ error }} </li>
- {% endfor %}
- </ul>
- {{ form.password }}
- {{ form.password.label }}
- <input type="submit" value="Submit">
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment