V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ns2250225
V2EX  ›  Python

请教: Django 怎样控制某个按钮的显示权限啊

  •  
  •   ns2250225 ·
    ns2250225 · 2017-11-19 11:24:18 +08:00 · 2550 次点击
    这是一个创建于 2321 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如标题

    3 条回复    2017-11-20 09:15:00 +08:00
    Macuilxochitl
        1
    Macuilxochitl  
       2017-11-19 13:21:12 +08:00   ❤️ 1
    用模板的 if 或者前端来控制
    flipped123
        2
    flipped123  
       2017-11-20 09:14:21 +08:00
    一楼说得对,在模板代码中 {% if self.has_perms('can view') %} <button>按钮</button>{% else %} nothing{% end if %}。关于判断用户是否具有某个权限的函数,你大可以去看官方文档,有好几个函数可以使用,我记不太清啦。
    flipped123
        3
    flipped123  
       2017-11-20 09:15:00 +08:00   ❤️ 1
    user.has_perms()
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5618 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 01:41 · PVG 09:41 · LAX 18:41 · JFK 21:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.