Skip to content

Commit a4ba5d4

Browse files
committed
update for book version 11
1 parent ccd15cb commit a4ba5d4

File tree

92 files changed

+3087
-39
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+3087
-39
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
30. staticファイルを追加
3636
31. ログイン認証のデコレータを作る
3737
32. Blueprintでアプリケーションを分割する
38-
33. テストを書く
39-
34. テストカバレッジの計測とレポートの作成
40-
35. 最終的なアプリケーション構成
41-
36. 最後に
38+
33. バージョン0.11対応: flaskコマンドラインを扱えるようにする
39+
34. バージョン1.0対応: アプリケーションファクトリを扱えるようにする
40+
35. テストを書く
41+
36. テストカバレッジの計測とレポートの作成
42+
37. 最終的なアプリケーション構成
43+
38. 最後に

section32/application/flask_blog/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
db = SQLAlchemy(app)
88

9-
from flask_blog.views.entries import entry
10-
11-
app.register_blueprint(entry, url_prefix='/users')
9+
from flask_blog.views.views import view
10+
app.register_blueprint(view)
1211

13-
from flask_blog.views import views
12+
from flask_blog.views.entries import entry
13+
app.register_blueprint(entry, url_prefix='/users')
0 Bytes
Binary file not shown.

section32/application/flask_blog/templates/layout.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
<ul class="nav navbar-nav navbar-right">
2222
{% if not session.logged_in %}
2323
<li class="nav-item">
24-
<a class="nav-link" href="{{ url_for('login') }}">ログイン</a>
24+
<a class="nav-link" href="{{ url_for('view.login') }}">ログイン</a>
2525
</li>
2626
{% else %}
2727
<li class="nav-item">
2828
<a class="nav-link" href="{{ url_for('entry.new_entry') }}">新規投稿</a>
2929
</li>
3030
<li class="nav-item">
31-
<a class="nav-link" href="{{ url_for('logout') }}">ログアウト</a>
31+
<a class="nav-link" href="{{ url_for('view.logout') }}">ログアウト</a>
3232
</li>
3333
{% endif %}
3434
</ul>

section32/application/flask_blog/templates/login.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends "layout.html" %} {% block body %}
2-
<form action="{{ url_for('login') }}" method=post>
2+
<form action="{{ url_for('view.login') }}" method=post>
33
<div class="form-group">
44
<label for="InputTitle">ユーザ名</label>
55
<input type="text" class="form-control" id="InputTitle" name=username>

section32/application/flask_blog/views/entries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ def delete_entry(id):
6666
db.session.delete(entry)
6767
db.session.commit()
6868
flash('投稿が削除されました')
69-
return redirect(url_for('entry.show_entries'))
69+
return redirect(url_for('entry.show_entries'))

section32/application/flask_blog/views/views.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
from flask import request, redirect, url_for, render_template, flash, session
22
from flask_blog import app
33
from functools import wraps
4+
from flask import Blueprint
45

6+
view = Blueprint('view', __name__)
57

68
def login_required(view):
79
@wraps(view)
810
def inner(*args, **kwargs):
911
if not session.get('logged_in'):
10-
return redirect(url_for('login'))
12+
return redirect(url_for('view.login'))
1113
return view(*args, **kwargs)
1214
return inner
1315

1416

15-
@app.route('/login', methods=['GET', 'POST'])
17+
@view.route('/login', methods=['GET', 'POST'])
1618
def login():
1719
error = None
1820
if request.method == 'POST':
@@ -27,12 +29,12 @@ def login():
2729
return render_template('login.html')
2830

2931

30-
@app.route('/logout')
32+
@view.route('/logout')
3133
def logout():
3234
session.pop('logged_in', None)
3335
flash('ログアウトしました')
3436
return redirect(url_for('entry.show_entries'))
3537

36-
@app.errorhandler(404)
38+
@view.app_errorhandler(404)
3739
def non_existant_route(error):
38-
return redirect(url_for('login'))
40+
return redirect(url_for('view.login'))

section33/application/flask_blog/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
db = SQLAlchemy(app)
88

9-
from flask_blog.views.entries import entry
10-
11-
app.register_blueprint(entry, url_prefix='/users')
9+
from flask_blog.views.views import view
10+
app.register_blueprint(view)
1211

13-
from flask_blog.views import views
12+
from flask_blog.views.entries import entry
13+
app.register_blueprint(entry, url_prefix='/users')
0 Bytes
Binary file not shown.

section33/application/flask_blog/templates/layout.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
<ul class="nav navbar-nav navbar-right">
2222
{% if not session.logged_in %}
2323
<li class="nav-item">
24-
<a class="nav-link" href="{{ url_for('login') }}">ログイン</a>
24+
<a class="nav-link" href="{{ url_for('view.login') }}">ログイン</a>
2525
</li>
2626
{% else %}
2727
<li class="nav-item">
2828
<a class="nav-link" href="{{ url_for('entry.new_entry') }}">新規投稿</a>
2929
</li>
3030
<li class="nav-item">
31-
<a class="nav-link" href="{{ url_for('logout') }}">ログアウト</a>
31+
<a class="nav-link" href="{{ url_for('view.logout') }}">ログアウト</a>
3232
</li>
3333
{% endif %}
3434
</ul>

0 commit comments

Comments
 (0)