Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def display_email(request):
username = request.session.get('user', '')
emails = Email.objects.get_queryset().order_by('email_id')
paginator = Paginator(emails, 12) # 生成paginator对象,设置每页显示15条记录
page = request.GET.get('page', 1) # 获取当前页为第1页
currentPage = int(page) # 把当前页转换成整数
try:
emails = paginator.page(page) # 获取当前页码数的记录列表
except PageNotAnInteger:
emails = paginator.page(1) # 如果输入的页数不是整数则显示第1页内容
except EmptyPage:
emails = paginator.page(paginator.num_pages) # 如果输入的的页数不在系统的页数中,则显示最后一页
return render(request, "email_add_page.html",{"user": username,"emails": emails})