python - NameError: Flask tutorial Flaskr step 4 -


i'm new python went through flaskr tutorial create simple chat flask. when got step 4 create database following error:

>>> import __init__ >>> init_db() traceback (most recent call last): file "<stdin>", line 1, in <module> file "__init__.py", line 34, in init_db db = get_db() file "__init__.py", line 29, in get_db g.sqlite_db = connect_db() file "__init__.py", line 22, in connect_db rv = sqlite3.connect(app.config['database']) nameerror: global name 'connect' not defined 

here __ init__.py:

# coding: utf-8 flask import flask, render_template, request, redirect, session, url_for, escape, g, abort, flash functools import wraps time import * import locale import os import sqlite3  app = flask(__name__) app.config.from_object(__name__) app.config.update(dict(     database='chat.db',     debug=true,     secret_key = "very secret",     username="user",     password="password" )) 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 get_db():     if not hasattr(g, "sqlite_db"):         g.sqlite_db = connect_db()     return g.sqlite_db  def init_db():     app.app_context():         db = get_db()         app.open_resource("schema.sql", mode="r") f:             db.cursor().executescript(f.read())         db.commit()  #some @app.route  @app.teardown_appcontext def close_db(error):     if hasattr(g, "sqlite_db"):         g.sqlite_db.close()  if __name__ == "__main__":     app.run(debug=true) 

here schema.sql:

drop table if exists entries;  create table entries (    id integer primary key autoincrement,   name text not null,   text text not null  ); 

flaskr tutorial step 4

sorry bad english, it's not first language. answers!

david

edit: i´m running on apche server mod_wsgi


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -