Advertisement
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
- app = Flask(__name__)
- app.config['SECRET_KEY'] = '123456'
- class LoginForm(FlaskForm):
- username = StringField('username')
- password = PasswordField('password')
- @app.route('/form', methods=['GET', 'POST'])
- def index():
- form = LoginForm()
- s = form.username.data
- s1 = form.password.data
- return f'Your username is {s} and your password is {s1}', render_template('index.html', form=form)
- if __name__ == "__main__":
- app.run(debug=True)
- <!DOCTYPE html>
- <html>
- <head>
- <title>Form!</title>
- </head>
- <body>
- <h1>Our form will be here!</h1>
- <form method="GET" action="{{ url_for('index') }}">
- {{ form.csrf_token }}
- {{ form.username.label }}
- {{ form.username }}
- {{ form.password.label }}
- {{ form.password }}
- <input type="submit" value="Submit">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement