1. <tfoot id='uKSkp'></tfoot>
        <bdo id='uKSkp'></bdo><ul id='uKSkp'></ul>

      1. <i id='uKSkp'><tr id='uKSkp'><dt id='uKSkp'><q id='uKSkp'><span id='uKSkp'><b id='uKSkp'><form id='uKSkp'><ins id='uKSkp'></ins><ul id='uKSkp'></ul><sub id='uKSkp'></sub></form><legend id='uKSkp'></legend><bdo id='uKSkp'><pre id='uKSkp'><center id='uKSkp'></center></pre></bdo></b><th id='uKSkp'></th></span></q></dt></tr></i><div id='uKSkp'><tfoot id='uKSkp'></tfoot><dl id='uKSkp'><fieldset id='uKSkp'></fieldset></dl></div>

        <small id='uKSkp'></small><noframes id='uKSkp'>

        <legend id='uKSkp'><style id='uKSkp'><dir id='uKSkp'><q id='uKSkp'></q></dir></style></legend>

        django - 使用 get_or_create 自动创建用户时设置用户权限

        时间:2023-11-08

          <legend id='sHI3A'><style id='sHI3A'><dir id='sHI3A'><q id='sHI3A'></q></dir></style></legend>
        • <i id='sHI3A'><tr id='sHI3A'><dt id='sHI3A'><q id='sHI3A'><span id='sHI3A'><b id='sHI3A'><form id='sHI3A'><ins id='sHI3A'></ins><ul id='sHI3A'></ul><sub id='sHI3A'></sub></form><legend id='sHI3A'></legend><bdo id='sHI3A'><pre id='sHI3A'><center id='sHI3A'></center></pre></bdo></b><th id='sHI3A'></th></span></q></dt></tr></i><div id='sHI3A'><tfoot id='sHI3A'></tfoot><dl id='sHI3A'><fieldset id='sHI3A'></fieldset></dl></div>
          <tfoot id='sHI3A'></tfoot>

          <small id='sHI3A'></small><noframes id='sHI3A'>

            • <bdo id='sHI3A'></bdo><ul id='sHI3A'></ul>

                <tbody id='sHI3A'></tbody>
                  本文介绍了django - 使用 get_or_create 自动创建用户时设置用户权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Django 1.5,python 2.6

                  Django 1.5, python 2.6

                  模型在特定条件下自动创建用户:

                  The model automatically creates a user under certain conditions:

                  User.objects.get_or_create(username=new_user_name, is_staff=True) 
                  u = User.objects.get(username=new_user_name)
                  u.set_password('temporary')
                  

                  除了设置用户名、密码和 is_staff 状态之外,我还想设置用户的权限 - 类似:

                  In addition to setting the username, password, and is_staff status, I would like to set the user's permissions - something like:

                  u.user_permissions('Can view poll')
                  

                  u.set_permissions('Can change poll')
                  

                  这可能吗?谢谢!

                  推荐答案

                  使用 addremove 方法:

                  Use add and remove methods:

                   from django.contrib.auth.models import Permission
                   permission = Permission.objects.get(name='Can view poll')
                   u.user_permissions.add(permission)
                  

                  这篇关于django - 使用 get_or_create 自动创建用户时设置用户权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:django-admin.py 不工作 下一篇:Django admin 很难定制吗?

                  相关文章

                    <bdo id='VVNFE'></bdo><ul id='VVNFE'></ul>
                  <legend id='VVNFE'><style id='VVNFE'><dir id='VVNFE'><q id='VVNFE'></q></dir></style></legend>
                  <tfoot id='VVNFE'></tfoot>

                      <i id='VVNFE'><tr id='VVNFE'><dt id='VVNFE'><q id='VVNFE'><span id='VVNFE'><b id='VVNFE'><form id='VVNFE'><ins id='VVNFE'></ins><ul id='VVNFE'></ul><sub id='VVNFE'></sub></form><legend id='VVNFE'></legend><bdo id='VVNFE'><pre id='VVNFE'><center id='VVNFE'></center></pre></bdo></b><th id='VVNFE'></th></span></q></dt></tr></i><div id='VVNFE'><tfoot id='VVNFE'></tfoot><dl id='VVNFE'><fieldset id='VVNFE'></fieldset></dl></div>

                      <small id='VVNFE'></small><noframes id='VVNFE'>