posts - 431,  comments - 344,  trackbacks - 0
def list(request):
    newses = News.objects.filter(active=True).order_by("-date")
    paginator = Paginator(newses, 8)
   
    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1
   
    try:
        finalNews = paginator.page(page)
    except (EmptyPage, InvalidPage):
        finalNews = paginator.page(paginator.num_pages)
   
    return render_to_response('news_list.html', {'newses':finalNews, 'count':newses.count(), 'numofpage':finalNews.object_list.count()})


{% load i18n%}
{% block content %}
<table width="800">
 {% for news in newses.object_list %}
 <tr>
  <td bgcolor="#EEEEEE" colspan="2">
   <a href="/news/{{news.id}}"class="left1">{{news.title}}</a>
  </td>
 </tr>
 <tr>
  <td align="left" bgcolor="#FFFFFF">{{news.date}}</td>
  <td align="left" bgcolor="#FFFFFF">类型:{{news.type}}</td>
 </tr>
 {% endfor%}
</table>

<table width="800">
 <tr>
  <td>
   总共{{count}}条信息&nbsp;&nbsp;&nbsp;
   <a href="?page=1">首页</a>&nbsp;&nbsp;&nbsp;
   {% if newses.has_previous %}
    <a href="?page={{ newses.previous_page_number }}">上一页</a>&nbsp;&nbsp;&nbsp;
   {% endif %}
   {% if newses.has_next %}
    <a href="?page={{ newses.next_page_number }}">下一页</a>&nbsp;&nbsp;&nbsp;
   {% endif %} 
    <a href="?page={{ newses.paginator.num_pages }}">尾页</a>&nbsp;&nbsp;&nbsp;
   {{ newses.number }} / {{newses.paginator.num_pages}} &nbsp;&nbsp;&nbsp;
   {{numofpage}}条/页
  </td>
 </tr>
</table>
{%endblock%}

posted on 2009-04-02 20:30 周锐 阅读(177) 评论(0)  编辑  收藏 所属分类: Python

只有注册用户登录后才能发表评论。


网站导航: