daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Oct 17th, 2017 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. with app.open_resource('schema.sql') as f:
  2. AttributeError: 'Flask' object has no attribute 'open_resourse'
  3.    
  4. import sqlite3
  5. import os
  6. from flask import Flask, request, session, g, redirect, url_for,
  7. abort, render_template, flash
  8. from contextlib import closing
  9.  
  10. DATABASE = '/tmp/flaskr.db'
  11. DEBUG = True
  12. SECRET_KEY = 'development key'
  13. USERNAME = 'admin'
  14. PASSWORD = 'default'
  15.  
  16. app = Flask(__name__)
  17. app.config.from_object(__name__)
  18.  
  19. app.config.update(dict(
  20.     DATABASE=os.path.join(app.root_path, 'flaskr.db'),
  21.     DEBUG=True,
  22.     SECRET_KEY='development key',
  23.     USERNAME='admin',
  24.     PASSWORD='default'
  25. ))
  26. app.config.from_envvar('FLASKR_SETTINGS', silent=True)
  27.  
  28. def connect_db():
  29.     rv = sqlite3.connect(app.config['DATABASE'])
  30.     rv.row_factory = sqlite3.Row
  31.     return rv
  32.  
  33. def init_db():
  34.     with closing(connect_db()) as db:
  35.         with app.open_resource('schema.sql') as f:
  36.             db.cursor().executescript(f.read())
  37.         db.commit()
  38.  
  39. def get_db():
  40.     if not hasattr(g, 'sqlite_db'):
  41.         g.sqlite_db = connect_db()
  42.     return g.sqlite_db
  43.  
  44. @app.teardown_appcontext
  45. def close_db(error):
  46.     if hasattr(g, 'sqlite_db'):
  47.         g.sqlite_db.close()
  48.  
  49. if __name__ == '__main__':
  50.     app.run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top