Python中文
首页
教程
问答
标签
搜索
登录
注册
FlaskAdmin基于角色的访问修改基于
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我从<a href="https://github.com/flask-admin/flask-admin/tree/master/examples/auth" rel="nofollow noreferrer">here</a>中获取了Flask Admin auth示例,并对其进行了一些更改。</p> <p>我在下面的视图中添加了以下块,但它不显示“导出”按钮。我希望它将导出选项添加到管理视图中。它确实将<code>---superuser</code>打印到控制台。</p> <pre><code> if current_user.has_role('superuser'): can_export = True print ' ---- superuser ' </code></pre> <p>我以前多次使用导出功能。如果我将语句<code>can_export = True</code>放在<code>class MyModelView(sqla.ModelView):</code>的正下方,它将起作用。我将此用作基于用户角色控制对创建/编辑/etc的访问的示例。例如,我希望有一个只读角色,其中can_create=False,can_edit=False,等等</p> <p>有人能帮忙吗?有人能告诉我我做错了什么吗?</p> <p>==</p> <p>这是整个视图。</p> <pre><code># Create customized model view class class MyModelView(sqla.ModelView): def is_accessible(self): if not current_user.is_active or not current_user.is_authenticated: return False if current_user.has_role('superuser'): return True return False def _handle_view(self, name, **kwargs): """ Override builtin _handle_view in order to redirect users when a view is not accessible. """ if current_user.has_role('superuser'): can_export = True print ' ---- superuser ' if not self.is_accessible(): if current_user.is_authenticated: # permission denied abort(403) else: # login return redirect(url_for('security.login', next=request.url)) </code></pre> <p>==</p> <p>作为参考:我把所有的代码<a href="https://github.com/dgleba/flaskplayground/blob/master/201roles/auth/app.py" rel="nofollow noreferrer">here</a>。</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>根据上面@dirn的注释,添加<code>self.</code>修复了它。</p> <pre><code>self.can_export = True </code></pre> <p>谢谢@dirn</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
使用Python创建一个非常大的二进制频率矩阵来运行协作过滤
4 回答
使用Python创建一张HTML网页,其中在不同颜色中重复n遍显示“Hello World”的方法
2 回答
使用Python创建一组唯一的值length L
3 回答
使用python创建不同表格的透视表
8 回答
使用python创建不和谐频道
5 回答
使用python创建不存在的多个文件夹
3 回答
使用python创建串行远程文件
10 回答
使用python创建交互式仪表板时出现问题
6 回答
使用python创建交互式绘图
4 回答
使用python创建交互式自动电子邮件
6 回答
使用Python创建价格列表
7 回答
使用python创建修改的txt文件
10 回答
使用Python创建全局变量,初始化后更改值
6 回答
使用Python创建关键字搜索词数组
10 回答
使用Python创建具有不均匀块大小/堆叠条形图的热图
4 回答
使用Python创建具有依赖于另一列的值的列
9 回答
使用Python创建具有多列的HTML表
2 回答
使用Python创建具有时间范围数据的等距数据帧
6 回答
使用Python创建具有特定顺序或属性的XML文件
1 回答
使用Python创建具有级联功能的搜索栏
1 回答