Collection of utilities for TurboGears2
Project description
About tgext.utils
tgext.utils is a collection of utilities for the TurboGears2 web framework.
Installing
tgext.utils can be installed from pypi:
pip install tgext.utils
should just work for most of the users.
CSRF Protection
tgext.utils.csrf provides two decorators @csrf_token and @csrf_protect which generate a CSRF token for inclusion in a form and check that the token is valid.
The user must apply @csrf_token decorator to the action that exposes the form, and put an <input type="hidden"> into the form with a request.csrf_token as the value and _csrf_token as name:
@csrf_token
@expose()
def form(self):
return '''
<form method="POST" action="/post_form">
<input type="hidden" name="_csrf_token" value="%s">
</form>''' % request.csrf_token
The action that receives the form must have @csrf_protect decorator, no particular action or check is required on this action:
@csrf_protect
@expose()
def post_form(self, **kwargs):
return 'OK!'
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
File details
Details for the file tgext.utils-0.0.2.tar.gz
.
File metadata
- Download URL: tgext.utils-0.0.2.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 879efea6aef2da28333b863b93539013671ee08cfc55ef43cf5ffd15fd0ec006 |
|
MD5 | 7c66ab9b37d81d2e35b9ddb65e4768b8 |
|
BLAKE2b-256 | 050e0ff7404efbc5a7d554a818b9c9dcddd35caa1ef57f7db9bcb2964079a5a5 |