All Projects → pyx → sanic-wtf

pyx / sanic-wtf

Licence: other
Sanic meets WTForms

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to sanic-wtf

Cookiecutter Sanic Microservice
A template for rapid development of Sanic based RESTful Microservices
Stars: ✭ 32 (+33.33%)
Mutual labels:  sanic
Sanic Cors
A Sanic extension for handling Cross Origin Resource Sharing (CORS), making cross-origin AJAX possible. Based on flask-cors by Cory Dolphin.
Stars: ✭ 143 (+495.83%)
Mutual labels:  sanic
pynaivechain
Python implementation of naivechain project
Stars: ✭ 18 (-25%)
Mutual labels:  sanic
Sanic Transmute
Easily document your Sanic API with Swagger UI, Plus param validation and model serialization.
Stars: ✭ 42 (+75%)
Mutual labels:  sanic
Sanic Nginx Docker Example
Sanic + Nginx + Docker basic example
Stars: ✭ 77 (+220.83%)
Mutual labels:  sanic
Asyncorm
Fully Async ORM inspired in django's
Stars: ✭ 182 (+658.33%)
Mutual labels:  sanic
Sanic Dispatcher
A Dispatcher extension for Sanic which also acts as a Sanic-to-WSGI adapter
Stars: ✭ 29 (+20.83%)
Mutual labels:  sanic
Metis
测试题小程序 包含后端api接口 可能会改成gitbook应用了吧
Stars: ✭ 79 (+229.17%)
Mutual labels:  sanic
Sanic session
Provides server-backed sessions for Sanic using Redis, Memcache and more.
Stars: ✭ 131 (+445.83%)
Mutual labels:  sanic
pait
Python Modern API Tools, fast to code
Stars: ✭ 24 (+0%)
Mutual labels:  sanic
Hproxy
hproxy - Asynchronous IP proxy pool, aims to make getting proxy as convenient as possible.(异步爬虫代理池)
Stars: ✭ 62 (+158.33%)
Mutual labels:  sanic
Graphql Server
This is the core package for using GraphQL in a custom server easily
Stars: ✭ 65 (+170.83%)
Mutual labels:  sanic
Sanic Jwt
Authentication, JWT, and permission scoping for Sanic
Stars: ✭ 189 (+687.5%)
Mutual labels:  sanic
Immuni Backend App Configuration
Repository for the backend app configuration
Stars: ✭ 33 (+37.5%)
Mutual labels:  sanic
json-head
JSON microservice for performing HEAD requests
Stars: ✭ 31 (+29.17%)
Mutual labels:  sanic
Immuni Backend Exposure Reporting
Repository for the Immuni's Exposure Reporting Service
Stars: ✭ 30 (+25%)
Mutual labels:  sanic
Owllook
owllook-小说搜索引擎
Stars: ✭ 2,163 (+8912.5%)
Mutual labels:  sanic
marshmallow-validators
Use 3rd-party validators (e.g. from WTForms and colander) with marshmallow
Stars: ✭ 24 (+0%)
Mutual labels:  wtforms
flask-wtf
Simple integration of Flask and WTForms, including CSRF, file upload and Recaptcha integration.
Stars: ✭ 1,357 (+5554.17%)
Mutual labels:  wtforms
Sanic
Async Python 3.7+ web server/framework | Build fast. Run fast.
Stars: ✭ 15,660 (+65150%)
Mutual labels:  sanic

Sanic-WTF - Sanic meets WTForms

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

Quick Start

Installation

pip install --upgrade Sanic-WTF

How to use it

Intialization (of Sanic)

from sanic import Sanic

app = Sanic(__name__)

# either WTF_CSRF_SECRET_KEY or SECRET_KEY should be set
app.config['WTF_CSRF_SECRET_KEY'] = 'top secret!'

@app.middleware('request')
async def add_session_to_request(request):
    # setup session

Defining Forms

from sanic_wtf import SanicForm
from wtforms import PasswordField, StringField, SubmitField
from wtforms.validators import DataRequired

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

That's it, just subclass SanicForm and later on passing in the current request object when you instantiate the form class. Sanic-WTF will do the trick.

Form Validation

from sanic import response

@app.route('/', methods=['GET', 'POST'])
async def index(request):
    form = LoginForm(request)
    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')
    # here, render_template is a function that render template with context
    return response.html(await render_template('index.html', form=form))

Note

For WTForms users: please note that SanicForm requires the whole request object instead of some sort of MultiDict.

For more details, please see documentation.

License

BSD New, see LICENSE for details.

Links

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].