Flask: current page in request variable

前端 未结 6 893
悲&欢浪女
悲&欢浪女 2020-12-04 16:41

In a template, how do I get what page I\'m currently on? I\'d rather not pass a variable like page , especially when I know some request.xxx can pr

6条回答
  •  星月不相逢
    2020-12-04 16:49

    To avoid using hard-coded URLs you can use the url_for function like this:

    {% for ni in ['index', 'foo', 'bar', 'baz'] %}
    
  • {{ ni | capitalize }}
  • {% endfor %}

    In this case index, foo, bar and baz would be function names, used like this in your python code:

    @app.route('/')
    def index():
    

提交回复
热议问题