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
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
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.