Updated the examples to be cli based
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 3be7d91 · Browse files · 6 files·+26 added−33 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+26 added−33 removed
- other:+26 added−33 removed
Provenance
- Commit
9ab5987- Tree
eec628d- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
3be7d91
6 files changed+26 added−33 removed
modified:examples/blueprintexample/blueprintexample.py+1 added-5 removed
2 unmodified lines3 4 app = Flask(__name__)5 app.register_blueprint(simple_page)6 # Blueprint can be registered many times7-app.register_blueprint(simple_page, url_prefix='/pages') 8-9-10-if __name__ == '__main__':11- app.run(debug=True)7+app.register_blueprint(simple_page, url_prefix='/pages')modified:examples/flaskr/README+10 added-3 removed
11 unmodified lines12 1. edit the configuration in the flaskr.py file or13 export an FLASKR_SETTINGS environment variable14 pointing to a configuration file.15 16- 2. now you can run the flaskr.py file with your17- python interpreter and the application will18- greet you on http://localhost:5000/16+ 2. initialize the database with this command:17+18+ flask --app=flaskr initdb19+20+ 3. now you can run flaskr:21+22+ flask --app=flaskr run23+24+ the application will greet you on25+ http://localhost:5000/26 27 ~ Is it tested?28 29 You betcha. Run the `flaskr_tests.py` file to see1 unmodified linemodified:examples/jqueryexample/jqueryexample.py-4 removed
21 unmodified lines22 23 @app.route('/')24 def index():25 return render_template('index.html')26-27-28-if __name__ == '__main__':29- app.run()modified:examples/minitwit/minitwit.py+7 added-12 removed
47 unmodified lines48 if hasattr(top, 'sqlite_db'):49 top.sqlite_db.close()50 51 52+@app.cli.command()52-def init_db():53+def initdb():54 """Creates the database tables."""54- with app.app_context():55- db = get_db()56- with app.open_resource('schema.sql', mode='r') as f:57- db.cursor().executescript(f.read())58- db.commit()55+ db = get_db()56+ with app.open_resource('schema.sql', mode='r') as f:57+ db.cursor().executescript(f.read())58+ db.commit()59 60 61 def query_db(query, args=(), one=False):62 """Queries the database and returns a list of dictionaries."""153 unmodified lines216 if request.method == 'POST':217 if not request.form['username']:218 error = 'You have to enter a username'219 elif not request.form['email'] or \220- '@' not in request.form['email']:220+ '@' not in request.form['email']:221 error = 'You have to enter a valid email address'222 elif not request.form['password']:223 error = 'You have to enter a password'224 elif request.form['password'] != request.form['password2']:22 unmodified lines247 248 # add some filters to jinja249 app.jinja_env.filters['datetimeformat'] = format_datetime250 app.jinja_env.filters['gravatar'] = gravatar_url251-252-253-if __name__ == '__main__':254- init_db()255- app.run()modified:examples/minitwit/README+8 added-5 removed
12 unmodified lines13 1. edit the configuration in the minitwit.py file or14 export an MINITWIT_SETTINGS environment variable15 pointing to a configuration file.16 17- 2. fire up a python shell and run this:17+ 2. fire up a shell and run this:18 19- >>> from minitwit import init_db; init_db()19+ flask --app=minitwit initdb20 21- 3. now you can run the minitwit.py file with your22- python interpreter and the application will23- greet you on http://localhost:5000/21+ 3. now you can run minitwit:22+23+ flask --app=minitwit run24+25+ the application will greet you on26+ http://localhost:5000/27 28 ~ Is it tested?29 30 You betcha. Run the `minitwit_tests.py` file to1 unmodified linemodified:examples/persona/persona.py-4 removed
51 unmodified lines52 out again.53 """54 session.clear()55 return 'OK'56-57-58-if __name__ == '__main__':59- app.run()