在Flas中链接一个路由到一个类

2024-10-03 00:30:08 发布

您现在位置:Python中文网/ 问答频道 /正文

enter image description here

我在看一个开源应用程序https://github.com/AlvinCJin/deepfit-app/tree/master/app

这是使用flask admin进行管理/在页面https://github.com/AlvinCJin/deepfit-app/blob/master/app/main/views.py

# admin management setup
admin.add_view(ModelView(User, db.session))
admin.add_view(ModelView(Post, db.session))
path = op.join(os.path.abspath(__file__ + "/../../"), 'static')  # need to get parent path of this code
admin.add_view(FileAdmin(path, '/static/', name='Static Files'))

这在生成有用的仪表板方面工作得很好,但不安全。在

我已经安装了flask login并阅读了http://flask-admin.readthedocs.io/en/latest/introduction/#rolling-your-own部分,但我不清楚如何链接所讨论的类:

^{pr2}$

管理路线。我已经习惯了将路由链接到flask中的模块函数,而不是类。在

如何做到这一点?在


Tags: pathhttpsgithubmastercomviewaddapp