Skip to main content
PyCon US is happening May 14th-22nd in Pittsburgh, PA USA.  Learn more

Use the ZODB with Flask

Project description

http://packages.python.org/Flask-ZODB/_static/flask-zodb.png

Transparent and scalable persistence of Python objects for Flask applications. Use it as your database or as a complement to another database - for example PostgreSQL where you need to perform rich queries and ZODB where you need structured data and mapping to and from Python types is inconvenient.

app = Flask(__name__)
db = ZODB(app)

@app.before_request
def set_db_defaults():
    if 'entries' not in db:
        db['entries'] = List()

@app.route('/')
def show_entries():
    return render_template('show_entries.html', entries=db['entries'])


@app.route('/add', methods=['POST'])
def add_entry():
    db['entries'].append(request.form)
    flash('New entry was successfully posted')
    return redirect(url_for('show_entries'))

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page