Python Django:切换活动用户
在这个项目中,我想在管理员登录时显示活动条,并显示蓝色,当其他用户登录时,我想在其上显示活动条,当用户不活动时,显示其他红色。 这是我的htmlPython Django:切换活动用户,python,django,django-rest-framework,Python,Django,Django Rest Framework,在这个项目中,我想在管理员登录时显示活动条,并显示蓝色,当其他用户登录时,我想在其上显示活动条,当用户不活动时,显示其他红色。 这是我的html <div class="card-body table-responsive p-0"> <table class="table table-hover text-nowrap" id="rooms"> <the
<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>
锡
使用者
电子邮件
地位
行动
{对象列表%中的用户为%0}
{{forloop.counter}
{{user.username}
{{user.email}
我不知道你的意思:活动用户还是非活动用户。但django中有一个经过身份验证的用户或匿名用户。所以你可以这样做:
{% if user.isauthenticated %} your css red or blue {% endfor %}
当管理员登录时,管理员切换应该是绿色的,其他用户切换应该是红色的。您可以检查用户是否是超级用户,并带有标志,{%if user.is_superuser%}您是绿色css{%endif%}