Advertisement
quantim

validate_on_submit not working

Oct 5th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.18 KB | None | 0 0
  1. ####### views.py #######
  2. from myapp import app
  3. import flask
  4. from forms import InventoryForm, LoginForm
  5.  
  6. @app.route('/login', methods=['POST', 'GET'])
  7. def login():
  8.     form = LoginForm()
  9.     if form.validate_on_submit():
  10.         return flask.redirect('/index')
  11.     return flask.render_template('login.html', form=form)
  12.  
  13. @app.route('/', methods=['GET', 'POST'])
  14. @app.route('/index', methods=['GET', 'POST'])
  15. def index():
  16.     return flask.render_template('index.html')
  17.  
  18. ####### forms.py #######
  19. from flask_wtf import FlaskForm
  20. from wtforms import StringField, PasswordField, BooleanField, SubmitField
  21. from wtforms.validators import DataRequired, InputRequired, Email, Length
  22.  
  23. class LoginForm(FlaskForm):
  24.     email = StringField('email', validators=[InputRequired(), Email(), Length(max=40)])
  25.     password = PasswordField('password', validators=[InputRequired()])
  26.     remember = BooleanField('remember me')
  27.     submit = SubmitField('submit')
  28.  
  29.  
  30. ####### login.html #######
  31. <!DOCTYPE html>
  32. <html>
  33. <head>
  34.   <title>Ansible UI</title>
  35.  
  36.   <!-- Latest compiled and minified CSS -->
  37.   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  38.   <!-- Custom styles for this template -->
  39.   <link href="/static/css/login.css" rel="stylesheet">
  40. </head>
  41.  
  42. <body>
  43.  
  44. <div class="container">
  45.  
  46.    <form class="form-signin" action="/index" method="POST">
  47.      {{ form.hidden_tag() }}
  48.      <h2 class="form-signin-heading">Please sign in</h2>
  49.      {{ form.email.label(class_="sr-only", for="inputEmail") }} {{ form.email(class_="form-control", id="inputEmail", placeholder="Email address")}}
  50.    </br>
  51.      {{ form.password.label(class_="sr-only", for="inputPassword") }} {{ form.password(class_="form-control", id="inputPassword", placeholder="Password") }}
  52.      <div class="checkbox">
  53.        <label>
  54.          {{ form.remember(type="checkbox", value="remember-me") }} Remember me
  55.        </label>
  56.      </div>
  57.      {{ form.submit(class_="btn btn-lg btn-primary btn-block", value="Sign in") }}
  58.    </form>
  59.  
  60.  </div> <!-- /container -->
  61. </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement