假设我创建了一个博客,它有三个像往常一样设置的静态路由。如果没有任何静态路由匹配,我希望我的方法 post_page() 通过在数据库中查找博客文章来返回答案:
/ → def index_page(): return "Index page"
/about → def index_page(): return "About page"
/contact → def index_page(): return "Contact page"
/<somethingelse> → def post_page(): return get_content(somethingelse)
一些示例 URL 将是:
http://localhost/ → show the index page
http://localhost/about → show the about page
http://localhost/contact → show the contact page
http://localhost/the-largest-known-prime-number → shows my log about the largest known prime number, it is fetched from the database.
http://localhost/my-cat → shows my log about my cat
http://localhost/my-dog → shows my log about my dog
使用 Flask 执行此操作的最佳方法是什么?如果可能的话,我仍然希望能够使用它url_for('about')
来查找我的静态路由的 URL。