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.
Links
Project details
Release history Release notifications | RSS feed
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.2.0.tar.gz
(8.6 kB
view hashes)
Built Distribution
Close
Hashes for Sanic_WTF-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 704818f754a5ca1b57d8066114b062d29a1ad237e257cf344842a2630e0eb497 |
|
MD5 | 1074a024a72b7f2cdf5b9419f5b9d2fe |
|
BLAKE2b-256 | e0b070c73c410b7820de519afbbd186f72c481133a14ec54d2abba1baad47e29 |