推荐学习书目
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 · Nov 19, 2017 · 3102 views
    This topic created in 3185 days ago, the information mentioned may be changed or developed.

    如标题

    3 replies    2017-11-20 09:15:00 +08:00
    Macuilxochitl
        1
    Macuilxochitl  
       Nov 19, 2017   ❤️ 1
    用模板的 if 或者前端来控制
    flipped123
        2
    flipped123  
       Nov 20, 2017
    一楼说得对,在模板代码中 {% if self.has_perms('can view') %} <button>按钮</button>{% else %} nothing{% end if %}。关于判断用户是否具有某个权限的函数,你大可以去看官方文档,有好几个函数可以使用,我记不太清啦。
    flipped123
        3
    flipped123  
       Nov 20, 2017   ❤️ 1
    user.has_perms()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   874 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 22:05 · PVG 06:05 · LAX 15:05 · JFK 18:05
    ♥ Do have faith in what you're doing.