How to generate dynamic urls in flask?

前端 未结 4 1025
长情又很酷
长情又很酷 2020-12-16 11:29

I have several records in the database which I Want to form URLs like so:

mysite.com/post/todays-post-will-be-about

The todays-post-will-b

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 11:40

    Use the @app.route decorator like shown below:

    @app.route('/post/')
    def show_post(post_title):
        #use post title to fetch the record from db
    

    More examples are available under the Routing section: http://flask.pocoo.org/docs/0.10/quickstart/#routing

提交回复
热议问题