First part of the tutorial. Many explanations missing but it's a start.

This commit is contained in:
Armin Ronacher 2010-04-15 02:21:46 +02:00
parent c4f5c2fb9a
commit 1246f4088a
9 changed files with 394 additions and 14 deletions

View file

@ -43,11 +43,8 @@ def init_db():
@app.request_init
def before_request():
"""Make sure we are connected to the database each request. Also
set `g.logged_in` to `True` if we are logged in.
"""
"""Make sure we are connected to the database each request."""
g.db = connect_db()
g.logged_in = session.get('logged_in', False)
@app.request_shutdown
@ -66,7 +63,7 @@ def show_entries():
@app.route('/add', methods=['POST'])
def add_entry():
if not g.logged_in:
if not session.get('logged_in'):
abort(401)
g.db.execute('insert into entries (title, text) values (?, ?)',
[request.form['title'], request.form['text']])

View file

@ -3,14 +3,15 @@ a, h1, h2 { color: #377BA8; }
h1, h2 { font-family: 'Georgia', serif; margin: 0; }
h1 { border-bottom: 2px solid #eee; }
h2 { font-size: 1.2em; }
div.metanav { text-align: right; font-size: 0.8em; background: #fafafa;
padding: 0.3em; margin-bottom: 1em; }
div.page { margin: 2em auto; width: 35em; border: 5px solid #ccc;
padding: 0.8em; background: white; }
ul.entries { list-style: none; margin: 0; padding: 0; }
ul.entries li { margin: 0.8em 1.2em; }
ul.entries li h2 { margin-left: -1em; }
div.page { margin: 2em auto; width: 35em; border: 5px solid #ccc;
padding: 0.8em; background: white; }
form.add-entry { font-size: 0.9em; border-bottom: 1px solid #ccc; }
form.add-entry dl { font-weight: bold; }
div.metanav { text-align: right; font-size: 0.8em; background: #fafafa;
padding: 0.3em; margin-bottom: 1em; }
div.flash { background: #CEE5F5; padding: 0.5em; border: 1px solid #AACBE2; }
p.error { background: #F0D6D6; padding: 0.5em; }

View file

@ -4,7 +4,7 @@
<div class=page>
<h1>Flaskr</h1>
<div class=metanav>
{% if not g.logged_in %}
{% if not session.logged_in %}
<a href="{{ url_for('login') }}">log in</a>
{% else %}
<a href="{{ url_for('logout') }}">log out</a>

View file

@ -7,7 +7,7 @@
<dt>Username:
<dd><input type=text name=username>
<dt>Password:
<dd><input type=passowrd name=password>
<dd><input type=password name=password>
<dd><input type=submit value=Login>
</dl>
</form>