Skip to main content

Sanic-WTF - WTForms meet Sanic

Project description

Sanic-WTF makes using WTForms with Sanic and CSRF (Cross-Site Request Forgery) protection a little bit easier.

Quick Start

Installation

pip install Sanic-WTF

How to use it

from sanic import Sanic
from sanic_wtf import SanicWTF
from wtforms import PasswordField, StringField, SubmitField
from wtforms.validators import DataRequired


app = Sanic(__name__)
wtf = SanicWTF(app)


class LoginForm(wtf.Form):
    name = StringField('Name', validators=[DataRequired()])
    password = PasswordField('Password', validators=[DataRequired()])
    submit = SubmitField('Sign In')


@app.route('/', methods=['GET', 'POST'])
def index(request):
    form = LoginForm(request.form):
    if request.method == 'POST' and form.validate():
        name = form.name.data
        password = form.password.data
        # check user password, log in user, etc.
        return response.redirect('/profile')
    return response.html('index.html', form=form)

if __name__ == '__main__':
    app.run(debug=True)

For more details, please see documentation.

License

BSD New, see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Sanic-WTF-0.1.0.tar.gz (8.7 kB view hashes)

Uploaded Source

Built Distribution

Sanic_WTF-0.1.0-py2.py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page