python - Stuck at Flask tutorial step 3 -


following flask tutorial, running win 7, python 2.7.3, virtualenv, , stuck in step 3: creating database http://flask.pocoo.org/docs/tutorial/dbinit/#tutorial-dbinit

such schema can created piping schema.sql file sqlite3 command follows:

sqlite3 /tmp/flaskr.db < schema.sql 

how run command, because cmd < venv > returns:

"sqlite3" not recognized internal or external command, operable program or batch file.

is step necessary?

folder project, 2 files schema.sql , flaskr.py.

schema.sql

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

flaskr.py

# imports import sqlite3 flask import flask, request, session, g, redirect, url_for, \ abort, render_template, flash contextlib import closing # 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_object(__name__) app.config.from_envvar('flaskr_settings', silent=true)   def connect_db():     return sqlite3.connect(app.config['database'])  def init_db():     closing(connect_db()) db:         app.open_resource('schema.sql') f:             db.cursor().executescript(f.read())         db.commit()  if __name__ == '__main__':     app.run() 

< venv > python

>>> flaskr import init_db >>> init_db() trackeback <most recent call last>: file "<stdin>", line 1, in <module> file "flaskr.py", line 24, in init_db   closing (connect_db()) db:  file "flaskr.py", line 21, in connect_db return sqlite3.connect(app.config['database']) sqlite3.operationalerror: unable open database. 

you confused between windows , unix filesystems.

find out sqllite.exe file exists on computer. lets in c:\sqllite. need determine create database file. /tmp/flaskr.db unix filesystem. on windows, should provide exact path or in current working directory. lets c:\flasktutorial.

to safe, might want create blank flaskr.db file first.

open notepad , create blank file @ `c:\flasktutorial\flaskr.db` 

now can run:

c:\sqllite\sqllite.exe c:\flasktutorial\flaskr.db < schema.sql 

also make sure in flaskr.py file, change database to:

database = 'c:\flasktutorial\flaskr.db' 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -