Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with app.open_resource('schema.sql') as f:
- AttributeError: 'Flask' object has no attribute 'open_resourse'
- import sqlite3
- import os
- from flask import Flask, request, session, g, redirect, url_for,
- abort, render_template, flash
- from contextlib import closing
- DATABASE = '/tmp/flaskr.db'
- DEBUG = True
- SECRET_KEY = 'development key'
- USERNAME = 'admin'
- PASSWORD = 'default'
- app = Flask(__name__)
- app.config.from_object(__name__)
- app.config.update(dict(
- DATABASE=os.path.join(app.root_path, 'flaskr.db'),
- DEBUG=True,
- SECRET_KEY='development key',
- USERNAME='admin',
- PASSWORD='default'
- ))
- app.config.from_envvar('FLASKR_SETTINGS', silent=True)
- def connect_db():
- rv = sqlite3.connect(app.config['DATABASE'])
- rv.row_factory = sqlite3.Row
- return rv
- def init_db():
- with closing(connect_db()) as db:
- with app.open_resource('schema.sql') as f:
- db.cursor().executescript(f.read())
- db.commit()
- def get_db():
- if not hasattr(g, 'sqlite_db'):
- g.sqlite_db = connect_db()
- return g.sqlite_db
- @app.teardown_appcontext
- def close_db(error):
- if hasattr(g, 'sqlite_db'):
- g.sqlite_db.close()
- if __name__ == '__main__':
- app.run()
Add Comment
Please, Sign In to add comment