Last active
December 19, 2015 02:49
-
-
Save dhrrgn/5886196 to your computer and use it in GitHub Desktop.
SeaSurf + Flask-WTF integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask.ext.wtf import DataRequired, TextField, PasswordField, Email | |
from seasurf_form import SeaSurfForm | |
class LoginForm(SeaSurfForm): | |
email = TextField('email', validators=[DataRequired(), Email()]) | |
password = PasswordField('password', validators=[DataRequired()]) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="post" action="{{ url_for('login') }}"> | |
{{ form.hidden_tag() }} | |
<p> | |
{{form.email.label }} {{ form.email(size=50) }} | |
</p> | |
<p> | |
{{form.password.label }} {{ form.password(size=50) }} | |
</p> | |
<p> | |
<input type="submit" value="Login"> | |
</p> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask.ext.wtf import Form, HiddenField | |
from flask import g | |
#import your app here | |
from wsgi import app | |
class SeaSurfForm(Form): | |
@staticmethod | |
@app.before_request | |
def add_csrf(): | |
csrf_name = app.config.get('CSRF_COOKIE_NAME', '_csrf_token') | |
setattr(SeaSurfForm, csrf_name, HiddenField(default=getattr(g, csrf_name))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment