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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 2 Python 3

File details

Details for the file Sanic-WTF-0.1.0.tar.gz.

File metadata

  • Download URL: Sanic-WTF-0.1.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Sanic-WTF-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0f519b6664568d5772f05d3a0377304b6c253bcbd2c9023ad10275a69c3fc7f3
MD5 24734f41e7ea4bf71cbd034470968280
BLAKE2b-256 1dd4b0a7d2dbab03d7a945469b8d4567b8d3fedbb63d686420332b6e2e97eab0

See more details on using hashes here.

Provenance

File details

Details for the file Sanic_WTF-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for Sanic_WTF-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6cf900b78ea5bc8b3e6b7cf3cfddb8aa5df1a7d79b17b98eb8cb7dc3c894f3c6
MD5 d6b6960b685ad286f40db0f41596b1d2
BLAKE2b-256 d6f7707e737e614dc2bce66a9e612cf218320c054d15e67e0a75a3b015311892

See more details on using hashes here.

Provenance

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