Guest User

Untitled

a guest
Nov 16th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. `from flask import Flask, render_template
  2. from flask_wtf import FlaskForm
  3. from wtforms import StringField, PasswordField, BooleanField
  4. from wtforms.validators import InputRequired, Email, length, ValidationError
  5.  
  6. app = Flask(__name__)
  7. app.config['SECRET_KEY'] = 'This is a secret'
  8. class LoginForm(FlaskForm):
  9. username = StringField('username', validators=[InputRequired()])
  10. password = PasswordField('password')
  11.  
  12. @app.route('/form', methods=['GET','POST'])
  13. def form():
  14. form=LoginForm()
  15. return render_template('form.html', form=form)
  16.  
  17.  
  18. if __name__== '__main__':
  19. app.run(debug=True)
  20.  
  21. <html>
  22. <title> MY FORM </title>
  23. <body>
  24. <form method="POST" action="{{ url_for('form') }}">
  25. {{form.csrf_token}}
  26. {{ form.username.label }}
  27. {{ form.username }}
  28. <ul>
  29. {% for error in form.username.errors %}
  30. <li style="color: red;">{{ error }} </li>
  31.  
  32. {% endfor %}
  33. </ul>
  34. {{ form.password }}
  35. {{ form.password.label }}
  36. <input type="submit" value="Submit">
  37.  
  38. </form>
  39. </body>
  40. </html>
Add Comment
Please, Sign In to add comment