Django FormView和分页
如果表单有效,我将使用django的FormView返回一组对象。 我的查看功能如下:Django FormView和分页,django,django-views,Django,Django Views,如果表单有效,我将使用django的FormView返回一组对象。 我的查看功能如下: class IdeaView(FormView): template_name = 'contributor/browse_photo.html' def get_form_class(self): return ContributorSearchForm def form_valid(self, form): cleaned_data = form
class IdeaView(FormView):
template_name = 'contributor/browse_photo.html'
def get_form_class(self):
return ContributorSearchForm
def form_valid(self, form):
cleaned_data = form.cleaned_data
filter_dict = {}
for key, value in cleaned_data.iteritems():
if key == 'colour' and cleaned_data['colour']:
filter_dict['colour_tag1'] = cleaned_data['colour']
if key == 'style' and cleaned_data['style']:
filter_dict['style_tag1'] = cleaned_data['style']
if key == 'material_type' and cleaned_data['material_type']:
filter_dict['material'] = cleaned_data['material_type']
if key == 'space' and cleaned_data['space']:
filter_dict['space_tag1'] = cleaned_data['space']
if key == 'sub_category' and cleaned_data['sub_category']:
filter_dict['space_sub_tag1'] = cleaned_data['sub_category']
contrib_images = ContributorImage.objects.filter(**filter_dict)
form = self.get_form_class()
form = form(initial=cleaned_data)
return render_to_response('contributor/browse_photo.html',
{'form':form,
'contrib_obj':contrib_images },
context_instance=RequestContext(self.request)
)
我想在contrib_图像上分页。我的问题是我想不出如何在这个方案中适合分页 Django提供了几个类,可以帮助您管理分页数据,即使用“上一页/下一页”链接拆分的数据。这些类位于
django/core/paginator.py
您要分页的内容是什么<代码>配置图像?因为问题在于分页是通过GET请求和
?page=…
参数工作的。如果我没弄错的话,formview可以与POST一起工作。@如果我想在Contribu图像上分页,我同意formview可以在POST上工作,而paginator可以在get上工作。。有出路吗!HTML是什么样子的?因为您可以手动执行分页器逻辑。例如,从self.request.POST.get('page',1)
中提取页码,然后在表单旁边添加一个prev/按钮,每次用户想要更改页面时只需重新发布即可。或者您可以尝试使用get params获取表单,但我不确定类是否允许这样做。