登录之后更新导航
@app.context_processor def mycontext(): usern=session.get('user') if usern: return{'username':usern} else: return{}
<p>{{ username }}一三</p>
{% if username %} <a href="#"> <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-log-in"></span>{{ username }} </button> </a> <a href="{{ url_for('logout') }}"> <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-user"></span> 注销 </button> </a> {% else %} <a href="{{ url_for('login') }}"> <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-log-in"></span>登录 </button> </a> <a href="{{ url_for('regist') }}"> <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-user"></span> 注册 </button> </a> {% endif %}<a href="#"> <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-log-in"></span>{{ username }} </button> </a> <a href="{{ url_for('logout') }}"> <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-user"></span> 注销 </button> </a> {% else %} <a href="{{ url_for('login') }}"> <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-log-in"></span>登录 </button> </a> <a href="{{ url_for('regist') }}"> <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-user"></span> 注册 </button> </a> {% endif %}
@app.route('/logout') def logout(): session.clear() return redirect(url_for('base'))