Skip to content

Instantly share code, notes, and snippets.

@solarce
Forked from Blue0ctober/flaskr.py
Created December 13, 2012 00:07
Show Gist options
  • Save solarce/4272890 to your computer and use it in GitHub Desktop.
Save solarce/4272890 to your computer and use it in GitHub Desktop.
#all the imports
from __future__ import with_statement
from contextlib import closing
import sqlite3
from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash
# configuration
DATABASE = "/tmp/flaskr.db"
DEBUG = True
SECRET_KEY = 'development key'
USERNAME = 'admin'
PASSWORD = 'default'
# create our little application
app = Flask(__name__)
app.config.from_envvar('FLASKR_SETTINGS', silent=True)
def connect_db():
return sqlite3.connect(DATABASE)
def init_db():
with closing(connect_db()) as db:
with app.open_resource('schema.sql') as f:
db.cursor().executescript(f.read())
db.commit()
if __name__ == '__main__':
app.run()
@solarce
Copy link
Author

solarce commented Dec 13, 2012

import flaskr
flaskr.init_db()
Traceback (most recent call last):
File "", line 1, in
File "flaskr.py", line 23, in init_db
with app.open_resource('schema.sql') as f:
File "/Library/Python/2.7/site-packages/flask/helpers.py", line 893, in open_resource
return open(os.path.join(self.root_path, resource), mode)
IOError: [Errno 2] No such file or directory: '/Users/bburton/code/flaskr/schema.sql'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment