python--django 实现 建议反馈管理页面 源码分享
作者:互联网
#反馈管理
def feedback_gl(request,pg_id=1):
uname=request.session.get("username","")
user_exist=bkuser.objects.filter(bkuser_name=uname)
admin_exist=bkadmin.objects.filter(bkadmin_name=uname)
feedbacklist=userfeedback.objects.all().filter().order_by("-feedbank_time")
nodata_msg="暂无数据"
#分页
paginator=Paginator(feedbacklist,10)
pg_id=int(pg_id)
try:
#获取当前页内容
feedbackpage=paginator.page(pg_id)
except PageNotAnInteger:
feedbackpage=paginator.page(1)
except InvalidPage:
feedbackpage=paginator.page(1)
except EmptyPage:
feedbackpage=paginator.page(paginator.num_pages)
if paginator.num_pages>5:
if pg_id-3<1:
pgrange=range(1,6)
elif pg_id+3>paginator.num_pages:
pgrange=range(paginator.num_pages-4,paginator.num_pages+1)
else:
pgrange=range(pg_id-2,pg_id+3)
else:
pgrange=paginator.page_range
if user_exist:
return redirect("/")
elif admin_exist:
return render(request,"feedback_gl.html",{"uname":uname,
"nodata_msg":nodata_msg,
"feedbackpage":feedbackpage,
"pgrange":pgrange,
"pg_id":pg_id,
"feedbacklist":feedbacklist,
"paginator":paginator,
"pgrange":pgrange
})
else:
return redirect("/bosslogin/")
对应的html源码
{% load customtag %}
<html>
<body style="overflow:hidden;">
<link href="/static/css/back.css" rel="stylesheet">
<link href="/static/css/custom.css" rel="stylesheet">
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
{% block iframeblock %}
<div class="app-container" style="overflow:hidden;">
<form class="userform">
</form>
<div class="usertable" >
<div class="tableheader"><table><thead><tr><th>反馈类型</th><th>反馈内容</th><th>反馈图片</th><th>反馈用户</th><th>反馈时间</th></tr></thead></table></div>
<div class="tableinfo"><table><tbody>
{% if feedbacklist|length == 0 %}
<p style="text-align:center;"> {{nodata_msg}}</p>
{% else %}
{% for feedback in feedbackpage.object_list %}
<tr>
<td><div class="cell"><span>{{feedback.feedbacklinksort_id|getfeedbacksort}}</span></div></td>
<td><div class="cell"><span>{{feedback.feedback_info}}</span></div></td>
<td><div class="cell"><span>{{feedback.feedbak_pic}}</span></div></td>
<td><div class="cell"><span>{{feedback.feedbacklinkuser_id|getusername}}</span></div></td>
<td><div class="cell"><span>{{feedback.feedbank_time|date:"Y-m-d H:i:s"}}</span></div></td>
</tr>
{% endfor %}
{% endif %}
</tbody></table></div>
</div>
<div class="userpag">
<div class="pag">
<ul class="pagination" >
<!-- 判断首页 -->
{% if pg_id == 1 %}
<li class="disabled"><a href="{% url 'feedback_gl' 1 %}">首页</a></li>
{% else %}
<li><a href="{% url 'feedback_gl' 1 %}">首页</a></li>
{% endif %}
<!-- 判断 上一页 -->
{% if feedbackpage.has_previous %}
<li><a href="{% url 'feedback_gl' feedbackpage.previous_page_number %}"><</a></li>
{% else %}
<li class="disabled"><a href=""><</a></li>
{% endif %}
{% for num in pgrange %}
{% if num == feedbackpage.number %}
<li class="active"><a href="{% url 'feedback_gl' num %}">{{num}}</a></li>
{% else %}
<li><a href="{% url 'feedback_gl' num %}">{{num}}</a></li>
{% endif %}
{% endfor %}
<!-- 判断下一页 -->
{% if feedbackpage.has_next %}
<li><a href="{% url 'feedback_gl' feedbackpage.next_page_number %}">></a></li>
{% else %}
<li class="disabled"><a href="">></a></li>
{% endif %}
<!-- 判断尾页 -->
{% if pg_id == paginator.num_pages %}
<li class="disabled"><a href="{% url 'feedback_gl' paginator.num_pages %}">尾页</a></li>
{% else %}
<li><a href="{% url 'feedback_gl' paginator.num_pages %}">尾页</a></li>
{% endif %}
</ul>
</div>
</div>
</div>
{% endblock %}
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/js/boss.js"></script>
<script src="/static/js/layer/layer.js"></script>
</body>
</html>
玩小程序“成语猜题”已开通流量主
标签:paginator,num,feedback,python,django,feedbackpage,源码,pg,id 来源: https://blog.csdn.net/zfs1570/article/details/112756577