Use finisher

-------------------------------------------------- ------- views file

 

def  guest(request):

  guest_list=a

  paginator = Paginator(guest_list, 2)

   page = request.GET.get('page')

   try:

     contacts = paginator.page(page)

  except PageNotAnInteger:

     contacts = paginator.page(1)

  except EmptyPage:

    contacts = paginator.page(paginator.num_pages)

  return render(request, "test.html", {"guests": contacts})

 

Wherein a is to obtain data from a database, where the library can be used to acquire data query MySQLdb required, the final format of the data becomes [{ 'first data: 001'}, { 'second data': 002 '}]

You may also be used to operate the database method of obtaining a guest_list = Event.objects.all ()

 

-------------------------------------------------- ----- test.html file

 

 <table class="table table-striped">

    <thead> 

      <tr>

        <Th> id </ th> <th> name </ th> <th> state </ th>

      </tr>

    </thead>

    <tbody>

      {% For athlete in guests%} here is to get out of a database query method of data presentation, if no paging, where guests are directly above a variable data acquired can be put over that views the file { "guests": guest_list})           

                   <td>{{ athlete.id }}</td>

                   <Td> {{athlete. Conference name}} </ td>

                   <Td> {{athlete. State 1}} </ td>

                  <tr>

      {% endfor %}

        </tbody>

       </table>

 

 <! - List pager ->

<div class="pagination">

  <span class="step-links">

  % IF guests.has_previous%} {           Guests, to show that the above data

<a href="?page={{ guests.previous_page_number }}">previous</a> {% endif %}

<span class="current">

Page {{ guests.number }} of {{ guests.paginator.num_pages }}.

     </span>

   {% if guests.has_next %}

<a href="?page={{ guests.next_page_number }}">next</a> {% endif %}

     </span>

   </div>

  </body>

 

 

Guess you like

Origin www.cnblogs.com/kaibindirver/p/11018765.html
use
use
Recommended