{"id":19715661,"url":"https://github.com/pyx/sanic-wtf","last_synced_at":"2025-04-29T20:30:39.493Z","repository":{"id":55644502,"uuid":"89646031","full_name":"pyx/sanic-wtf","owner":"pyx","description":"Sanic meets WTForms","archived":false,"fork":false,"pushed_at":"2023-10-06T02:13:09.000Z","size":76,"stargazers_count":26,"open_issues_count":5,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-05T19:03:02.686Z","etag":null,"topics":["csrf-protection","sanic","wtforms"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pyx.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-04-27T22:39:13.000Z","updated_at":"2024-01-12T13:00:40.000Z","dependencies_parsed_at":"2022-08-15T05:20:45.577Z","dependency_job_id":null,"html_url":"https://github.com/pyx/sanic-wtf","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyx%2Fsanic-wtf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyx%2Fsanic-wtf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyx%2Fsanic-wtf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyx%2Fsanic-wtf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pyx","download_url":"https://codeload.github.com/pyx/sanic-wtf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251578252,"owners_count":21611999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csrf-protection","sanic","wtforms"],"created_at":"2024-11-11T22:39:05.544Z","updated_at":"2025-04-29T20:30:39.239Z","avatar_url":"https://github.com/pyx.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"===============================\nSanic-WTF - Sanic meets WTForms\n===============================\n\nSanic-WTF makes using `WTForms`_ with `Sanic`_ and CSRF (Cross-Site Request\nForgery) protection a little bit easier.\n\n\n.. _WTForms: https://wtforms.readthedocs.io/en/3.0.x/\n.. _Sanic: https://github.com/channelcat/sanic\n\n\nQuick Start\n===========\n\n\nInstallation\n------------\n\n.. code-block:: sh\n\n  pip install --upgrade Sanic-WTF\n\n\nHow to use it\n-------------\n\n\nIntialization (of Sanic)\n^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n  from sanic import Sanic\n\n  app = Sanic(__name__)\n\n  # either WTF_CSRF_SECRET_KEY or SECRET_KEY should be set\n  app.config['WTF_CSRF_SECRET_KEY'] = 'top secret!'\n\n  @app.middleware('request')\n  async def add_session_to_request(request):\n      # setup session\n\n\nDefining Forms\n^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n  from sanic_wtf import SanicForm\n  from wtforms.fields import PasswordField, StringField, SubmitField\n  from wtforms.validators import DataRequired\n\n  class LoginForm(SanicForm):\n      name = StringField('Name', validators=[DataRequired()])\n      password = PasswordField('Password', validators=[DataRequired()])\n      submit = SubmitField('Sign In')\n\nThat's it, just subclass `SanicForm` and later on passing in the current\n`request` object when you instantiate the form class.  Sanic-WTF will do the\ntrick.\n\n\nForm Validation\n^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n  from sanic import response\n\n  @app.route('/', methods=['GET', 'POST'])\n  async def index(request):\n      form = LoginForm(request)\n      if request.method == 'POST' and form.validate():\n          name = form.name.data\n          password = form.password.data\n          # check user password, log in user, etc.\n          return response.redirect('/profile')\n      # here, render_template is a function that render template with context\n      return response.html(await render_template('index.html', form=form))\n\n\n.. note::\n  For WTForms users: please note that `SanicForm` requires the whole `request`\n  object instead of some sort of `MultiDict`.\n\n\nFor more details, please see documentation.\n\n\nLicense\n=======\n\nBSD New, see LICENSE for details.\n\n\nLinks\n=====\n\n- `Documentation \u003chttp://sanic-wtf.readthedocs.org/\u003e`_\n\n- `Issue Tracker \u003chttps://github.com/pyx/sanic-wtf/issues/\u003e`_\n\n- `Source Package @ PyPI \u003chttps://pypi.python.org/pypi/sanic-wtf/\u003e`_\n\n- `Git Repository @ Github\n  \u003chttps://github.com/pyx/sanic-wtf/\u003e`_\n\n- `Git Repository @ Gitlab\n  \u003chttps://gitlab.com/pyx/sanic-wtf/\u003e`_\n\n- `Development Version\n  \u003chttp://github.com/pyx/sanic-wtf/zipball/master#egg=sanic-wtf-dev\u003e`_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyx%2Fsanic-wtf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpyx%2Fsanic-wtf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyx%2Fsanic-wtf/lists"}