Skip to main content

csrf plugin for bottle

Project description

csrf support for bottle
server.py
---------
#!/usr/bin/env python
#coding: utf-8
__author__ = 'spouk'

from bottle import Bottle, template, TEMPLATE_PATH
from spouk_bottle_csrf import CSRF

CSRF_SALT = 'somesalforcsrf'
csrf = CSRF(CSRF_SALT=CSRF_SALT)

app=Bottle()
TEMPLATE_PATH.append('template/')
app.install(csrf)


# пример декоратора
@app.csrf.csrf_decorator
def mainrender(page, *argc,**kwargs):
kwargs.update(dict(app=app))
result = template(page, *argc, **kwargs)
# app.csrf.csrf_check_after_request(result)
return template(page, *argc, **kwargs)

@app.get('/')
def root():
print app.csrf.csrf_token, app.csrf.csrf_meta_geting
return mainrender('index.html')

app.run(host='localhost',port=3500, debug=True,reloader=True)



index.html
----------
<html>
<head>
<meta charset="utf-8" />
<meta content="{{app.csrf.csrf_token}}" name="csrf-token">
</head>
<body>

Csrf_token: {{ app.csrf.csrf_token }} <br />
example visible `hidden` input form: {{ app.csrf.csrf_token_html }} <br />
example `hidden` form: {{ !app.csrf.csrf_token_html }} <br />
</body>
</html>


---
Copyleft [x] 2015, Spouk

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for spouk-bottle-csrf, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size spouk-bottle-csrf-0.0.1.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page