From 9ab59871007c12fad03f43ac08f889e4c080e64d Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 29 Apr 2014 01:48:31 +0200 Subject: [PATCH] Updated the examples to be cli based --- examples/blueprintexample/blueprintexample.py | 6 +----- examples/flaskr/README | 13 ++++++++++--- examples/jqueryexample/jqueryexample.py | 4 ---- examples/minitwit/README | 13 ++++++++----- examples/minitwit/minitwit.py | 19 +++++++------------ examples/persona/persona.py | 4 ---- 6 files changed, 26 insertions(+), 33 deletions(-) diff --git a/examples/blueprintexample/blueprintexample.py b/examples/blueprintexample/blueprintexample.py index bc0e41d4..925f4845 100644 --- a/examples/blueprintexample/blueprintexample.py +++ b/examples/blueprintexample/blueprintexample.py @@ -4,8 +4,4 @@ from simple_page.simple_page import simple_page app = Flask(__name__) app.register_blueprint(simple_page) # Blueprint can be registered many times -app.register_blueprint(simple_page, url_prefix='/pages') - - -if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file +app.register_blueprint(simple_page, url_prefix='/pages') diff --git a/examples/flaskr/README b/examples/flaskr/README index 9b5b9215..fc555388 100644 --- a/examples/flaskr/README +++ b/examples/flaskr/README @@ -13,9 +13,16 @@ export an FLASKR_SETTINGS environment variable pointing to a configuration file. - 2. now you can run the flaskr.py file with your - python interpreter and the application will - greet you on http://localhost:5000/ + 2. initialize the database with this command: + + flask --app=flaskr initdb + + 3. now you can run flaskr: + + flask --app=flaskr run + + the application will greet you on + http://localhost:5000/ ~ Is it tested? diff --git a/examples/jqueryexample/jqueryexample.py b/examples/jqueryexample/jqueryexample.py index 08164119..034cc495 100644 --- a/examples/jqueryexample/jqueryexample.py +++ b/examples/jqueryexample/jqueryexample.py @@ -23,7 +23,3 @@ def add_numbers(): @app.route('/') def index(): return render_template('index.html') - - -if __name__ == '__main__': - app.run() diff --git a/examples/minitwit/README b/examples/minitwit/README index ab946295..873ceb8e 100644 --- a/examples/minitwit/README +++ b/examples/minitwit/README @@ -14,13 +14,16 @@ export an MINITWIT_SETTINGS environment variable pointing to a configuration file. - 2. fire up a python shell and run this: + 2. fire up a shell and run this: - >>> from minitwit import init_db; init_db() + flask --app=minitwit initdb - 3. now you can run the minitwit.py file with your - python interpreter and the application will - greet you on http://localhost:5000/ + 3. now you can run minitwit: + + flask --app=minitwit run + + the application will greet you on + http://localhost:5000/ ~ Is it tested? diff --git a/examples/minitwit/minitwit.py b/examples/minitwit/minitwit.py index 913d4522..0a85247b 100644 --- a/examples/minitwit/minitwit.py +++ b/examples/minitwit/minitwit.py @@ -49,13 +49,13 @@ def close_database(exception): top.sqlite_db.close() -def init_db(): +@app.cli.command() +def initdb(): """Creates the database tables.""" - with app.app_context(): - db = get_db() - with app.open_resource('schema.sql', mode='r') as f: - db.cursor().executescript(f.read()) - db.commit() + db = get_db() + with app.open_resource('schema.sql', mode='r') as f: + db.cursor().executescript(f.read()) + db.commit() def query_db(query, args=(), one=False): @@ -217,7 +217,7 @@ def register(): if not request.form['username']: error = 'You have to enter a username' elif not request.form['email'] or \ - '@' not in request.form['email']: + '@' not in request.form['email']: error = 'You have to enter a valid email address' elif not request.form['password']: error = 'You have to enter a password' @@ -248,8 +248,3 @@ def logout(): # add some filters to jinja app.jinja_env.filters['datetimeformat'] = format_datetime app.jinja_env.filters['gravatar'] = gravatar_url - - -if __name__ == '__main__': - init_db() - app.run() diff --git a/examples/persona/persona.py b/examples/persona/persona.py index d56f299a..7374c3af 100644 --- a/examples/persona/persona.py +++ b/examples/persona/persona.py @@ -53,7 +53,3 @@ def logout_handler(): """ session.clear() return 'OK' - - -if __name__ == '__main__': - app.run()