Django implements the rolling Loading Function

Source: Internet
Author: User

We are using django as a community website notewo.com. In fact, we want to implement the rolling loading function like google +. I have been thinking about how to do it.

The steps are as follows:

Step 1: implement the paging function of django.

 

 
 
  1. Vim views. py
  2. From django. core. paginator import Paginator, InvalidPage, EmptyPage
  3.  
  4.  
  5. Def myBlog (request ):
  6. Form = PostForm (request. POST)
  7. Commentform = CommentForm ()
  8. Posts_list = Blog. objects. order_by ('-date'). all ()
  9. Paginator = Paginator (posts_list, 20) # display 20 records
  10. Try:
  11. Page = int (request. GET. get ('page', '1 '))
  12. Failed t ValueError:
  13. Page = 1
  14.  
  15. Try:
  16. Posts = paginator. page (page)
  17. Metadata T (EmptyPage, InvalidPage ):
  18. Posts = paginator. page (paginator. num_pages)
  19. T = get_template ('notewo/blog.html ')
  20. C = RequestContext (request, locals ())
  21. Return HttpResponse (t. render (c ))

 

 
 
  1. {% For post in posts. object_list %}
  2. <Li class = "box bloglist">
  3. (Here you can just put your html code)
  4. </Li>
  5. {% Endfor %}
  6. <Li class = "page">
  7. <Div class = "pagination">
  8. <Span class = "step-links">
  9. {% If posts. has_previous %}
  10. <A href = "? Page ={{ posts. previus_page_number }}"> previous </a>
  11. {% Endif %}
  12.  
  13. <Span class = "current">
  14. Page {posts. number }}of {posts. paginator. num_pages }}.
  15. </Span>
  16.  
  17. {% If posts. has_next %}
  18. <A href = "? Page = {posts. next_page_number} "class =" nextpage "> next </a>
  19. <A class = "nextpage2"> next </a>
  20. {% Endif %}
  21. </Span>
  22. </Div>
  23. </Li>

Step 2,

You should note that I wrote the following:

 

 
 
  1. <a   class="nextpage2">next</a>  

. The younger brother is not talented. He can only use this stupid method. Continue

 

 
 
  1. Function getnextpage (){
  2.  
  3. $ (". Nextpage2"). click (function (){
  4. Var href = $ (". nextpage"). attr ("href ");
  5. Console. log (href );
  6. $. Ajax ({
  7. Type: "get ",
  8. Url: href,
  9. Success: function (data ){
  10. Var html = $ (data). find (". showblog" pai.html ();
  11. $ (". Pageli"). remove ();
  12. $ (". Showblog"). append (html );
  13. // Rebind a click event
  14. Getnextpage ();
  15. }
  16. }); // End ajax
  17. }); // End $ (". nextpage)
  18. }

$ (". Showblog") is the top-level ul

When $ (". nextpage2") is clicked, $ (". nextpage") is triggered to capture the returned data and add the li data to the end of ul.

If you want to automatically scroll to the bottom, it is no longer difficult to improve it. Sleeping

 

 

 

This article is from the "YEELON sources" blog, please be sure to keep this source http://yeelone.blog.51cto.com/1476571/940474

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.