使用Django无限滚动获取帖子

问题描述

JS代码:- 我在添加以下js代码时无法加载帖子。我在视图中定义了get和post方法,但是没有用。

var infinite = new Waypoint.Infinite({
element: $('.infinite-container')[0],handler: function(direction) {

},offset: 'bottom-in-view',onBeforePageLoad: function () {
    $('.spinner-border').show();
},onAfterPageLoad: function () {
    $('.spinner-border').hide();
}

});

我的查看功能:-

class IndexView(ListView):
model = Posts
paginate_by = 4
context_object_name = 'content'
template_name = 'dashboard.html'
form = PostsForm

def get(self,request,*args,**kwargs):
    post_form = self.form()
    return render( request,self.template_name,{ 'post_form' : post_form } )

def post(self,**kwargs):
    post_form = self.form( request.POST,request.FILES )
    if post_form.is_valid():
        current_user = User.objects.get( id = request.user.id )
        post_title = request.POST.get( 'title',False )
        post_content = request.POST.get( 'content',False )
        post_tags = request.POST.get( 'tags',False )
        post_source = request.POST.get( 'source',False )
        post_form = Posts( title = post_title,slug = slugify( post_title ),user = current_user,content = post_content,tags = post_tags,source = post_source )
        post_form.save()
        messages.success( request,'Visit My Post section to find out how it looks')
        return redirect( 'micro__blog:dashboard' )
    else:
        messages.error( request,"Error while saving,try again." )
    return render( request,{ 'post_form' : post_form } )

感谢您的帮助

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...