Flask ではルートを指定して動作を指定します。動作は関数で記述します。Flask は指定された関数を起動します。
引数を指定することもできます。引数は<引数>の形で指定、関数の引数で受け継ぎます。この引数を省略できるのか、っていう問題です。
Python の関数はデフォルト値を持つ引数は省略できます。そのノリでそのまま引数のデフォルト値を指定してもルートは判別しません。
ここは引数なしのルートを指定してやります。関数のほうはデフォルト値を指定することで対処します。ここでルートの最後の/(スラッシュ)を指定します。
これで url_for() で引数を省略できます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ app.route('/mbr/profile/') | |
@ app.route('/mbr/profile/<member_username>') | |
def mbr_profile(member_username=None): | |
pass |