1

I am a newbie - just reached the end of Learn Python the Hard Way and am now trying my hand at Flask. I started with the official tutorial at the Flask website, but am getting stuck at this step:

from __future__ import with_statement
import sqlite3
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.from_envvar('FLASKR_SETTINGS',silent=True)

def connect_db():
        return sqlite3.connect(app.config['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()

At the Python Shell, if I do

from flaskr import init_db
init_db() 

I see: Attribute Error: Flask object has no attribute 'open' (in the line containing app.open.resource in init_db). How do i fix this?

1 Answer 1

2

Your code:

app.open.resource

The example code:

app.open_resource

Can you spot the difference? In case you can't, the example code uses an underscore where you use a dot. A Flask object has no attribute called open, but it does have a method called open_resource.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.