Updated the examples to be cli based
This commit is contained in:
parent
3be7d918ce
commit
9ab5987100
6 changed files with 26 additions and 33 deletions
|
|
@ -5,7 +5,3 @@ app = Flask(__name__)
|
||||||
app.register_blueprint(simple_page)
|
app.register_blueprint(simple_page)
|
||||||
# Blueprint can be registered many times
|
# Blueprint can be registered many times
|
||||||
app.register_blueprint(simple_page, url_prefix='/pages')
|
app.register_blueprint(simple_page, url_prefix='/pages')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
app.run(debug=True)
|
|
||||||
|
|
@ -13,9 +13,16 @@
|
||||||
export an FLASKR_SETTINGS environment variable
|
export an FLASKR_SETTINGS environment variable
|
||||||
pointing to a configuration file.
|
pointing to a configuration file.
|
||||||
|
|
||||||
2. now you can run the flaskr.py file with your
|
2. initialize the database with this command:
|
||||||
python interpreter and the application will
|
|
||||||
greet you on http://localhost:5000/
|
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?
|
~ Is it tested?
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,3 @@ def add_numbers():
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
app.run()
|
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,16 @@
|
||||||
export an MINITWIT_SETTINGS environment variable
|
export an MINITWIT_SETTINGS environment variable
|
||||||
pointing to a configuration file.
|
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
|
3. now you can run minitwit:
|
||||||
python interpreter and the application will
|
|
||||||
greet you on http://localhost:5000/
|
flask --app=minitwit run
|
||||||
|
|
||||||
|
the application will greet you on
|
||||||
|
http://localhost:5000/
|
||||||
|
|
||||||
~ Is it tested?
|
~ Is it tested?
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,13 +49,13 @@ def close_database(exception):
|
||||||
top.sqlite_db.close()
|
top.sqlite_db.close()
|
||||||
|
|
||||||
|
|
||||||
def init_db():
|
@app.cli.command()
|
||||||
|
def initdb():
|
||||||
"""Creates the database tables."""
|
"""Creates the database tables."""
|
||||||
with app.app_context():
|
db = get_db()
|
||||||
db = get_db()
|
with app.open_resource('schema.sql', mode='r') as f:
|
||||||
with app.open_resource('schema.sql', mode='r') as f:
|
db.cursor().executescript(f.read())
|
||||||
db.cursor().executescript(f.read())
|
db.commit()
|
||||||
db.commit()
|
|
||||||
|
|
||||||
|
|
||||||
def query_db(query, args=(), one=False):
|
def query_db(query, args=(), one=False):
|
||||||
|
|
@ -217,7 +217,7 @@ def register():
|
||||||
if not request.form['username']:
|
if not request.form['username']:
|
||||||
error = 'You have to enter a username'
|
error = 'You have to enter a username'
|
||||||
elif not request.form['email'] or \
|
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'
|
error = 'You have to enter a valid email address'
|
||||||
elif not request.form['password']:
|
elif not request.form['password']:
|
||||||
error = 'You have to enter a password'
|
error = 'You have to enter a password'
|
||||||
|
|
@ -248,8 +248,3 @@ def logout():
|
||||||
# add some filters to jinja
|
# add some filters to jinja
|
||||||
app.jinja_env.filters['datetimeformat'] = format_datetime
|
app.jinja_env.filters['datetimeformat'] = format_datetime
|
||||||
app.jinja_env.filters['gravatar'] = gravatar_url
|
app.jinja_env.filters['gravatar'] = gravatar_url
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
init_db()
|
|
||||||
app.run()
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,3 @@ def logout_handler():
|
||||||
"""
|
"""
|
||||||
session.clear()
|
session.clear()
|
||||||
return 'OK'
|
return 'OK'
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
app.run()
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue