【问题标题】:Django: Toggle active usersDjango:切换活跃用户
【发布时间】:2021-05-23 11:56:21
【问题描述】:

在这个项目中,我想在管理员登录时显示活动栏并显示蓝色,当任何其他用户登录时,我想在用户登录时显示活动栏和其他红色不活跃。 这是我的html

<div class="card-body table-responsive p-0">
            <table class="table table-hover text-nowrap" id="rooms">
              <thead>
                <tr>
                  <th>SN</th>
                  <th>Users</th>
                  <th>Email</th>
                  <th>Status</th>
                  <th>Action</th>
                </tr>
              </thead>
              <tbody>
                {% for user in object_list %}
                <tr>
                  <td>{{forloop.counter}}</td>
                  <td>{{user.username }}</td>
                  <td>{{user.email}}</td>
                  <td>
                   <label class="switch">
                      <input type="checkbox">
                      <span class="slider round"></span>
                    </label>
                  </td>
                  <td>
                      <span ><a class="btn btn-info mr-2" href="{% url 'dashboard:passwordreset'  %}"
                          ><i
                            class="fa fa-edit m-1"
                            aria-hidden="true"
                          ></i>Reset Password</a
                      ></span>
                  </td> 
                </tr>
                {% endfor %}
              </tbody>
            </table>
            
            </div>
          </div>

Here I want to show green when admin is logged in and other active when other user is logged in

【问题讨论】:

    标签: python django django-rest-framework


    【解决方案1】:

    我不知道你是什么意思:活跃用户或非活跃用户。但是 django 中有经过身份验证的用户或匿名用户。所以你可以这样做:

        {% if user.isauthenticated %} your css red or blue {% endfor %}
    
    
    

    【讨论】:

    • 当管理员登录后,管理员切换应为绿色,其他用户切换应为红色。
    • 你可以检查用户是否是带有标志的超级用户,{% if user.is_superuser %} 你是绿色 css {% endif %}
    猜你喜欢
    • 1970-01-01
    • 2011-05-14
    • 2013-11-12
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多