django - ' float' object不能解释为整数

时间:2014-04-09 13:15:04

标签: python django

当我使用python 2.7时,代码工作正常。 但是当我安装python 3.4和runserver时,我发生了类型错误 在以“return render_to_response”(3位)开头的行上。

异常值是“'float'对象不能被解释为整数”。 我不确定此错误是由版本差异引起的。

代码写在下面。

谢谢。

def notice(request, page_id = 1): 

  context = RequestContext(request)
  if not request.user.has_perm("board/category1_can_read"):
    return HttpResponseRedirect(request.path)
  post_list = Post.objects.filter(category=1)[::-1]
  cut = len(post_list)/6
  if not len(post_list)%6:
    cut -= 1
  if (cut <= 0) and (1 < page_id):
    max_page = 1
    raise Http404
  else:
    max_page = cut + 1
  i = int(page_id) - 1

  post_list = post_list[i*6:(i+1)*6] #divide post list into pages (6 post per page)

  return render_to_response("board/notice.html", {"board_active": "active", "post_list": post_list, "page_id": int(page_id), "max_page": range(max_page)}, context)




def boardA(request, category_id = 2, page_id = 1):

  context = RequestContext(request)
  if not request.user.has_perm("board/category2_can_read"):
    return HttpResponseRedirect(request.path)
  if 0 == int(category_id): #selected All post
    post_list = Post.objects.all()[::-1]
  else:
    post_list = Post.objects.filter(category=int(category_id))[::-1]
  cut = len(post_list)/6
  if not len(post_list)%6:
    cut -= 1
  if (cut <= 0) and (1 < page_id):
    max_page = 1
    raise Http404
  else:
    max_page = cut + 1
  i = int(page_id) - 1
  post_list = post_list[i*6:(i+1)*6]
  return render_to_response("board/boardA.html", {"boardA_active": "active", "post_list": post_list, "category_id": int(category_id), "page_id": int(page_id), "max_page": range(max_page)}, context)


def boardB(request, page_id = 1):

      context = RequestContext(request)
  if not request.user.has_perm("board/category3_can_read"):
    return HttpResponseRedirect(request.path)
  post_list = Post.objects.filter(category=3)  
  cut = len(post_list)/6
  if not len(post_list)%6:
    cut -= 1
  if (cut <= 0) and (1 < page_id):
    max_page = 1
    raise Http404
  else:
    max_page = cut + 1
  i = int(page_id) - 1
  post_list = post_list[i*6:(i+1)*6]
  return render_to_response("board/boardB.html", {"boardB_active": "active", "post_list": post_list, "page_id": int(page_id), "max_page": range(max_page)}, context)

0 个答案:

没有答案