我试图使用分页,但它给了我这个错误:
public class ColorSortConverter : IValueConverter
{
public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
{
PropertyInfo[] colorsProperties = null;
var result = value as PropertyInfo[] ;
if (result != null)
{
colorsProperties = result;
colorsProperties.OrderBy(i => i.Name).ToArray();
return colorsProperties;
}
return colorsProperties;
}
}
这是我用于表格分页的部分。 models.py
Traceback (most recent call last):
File "/home/omega/venv/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/omega/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/omega/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/srv/tester/tables/views.py", line 44, in addview
details = paginator.page(1)
File "/home/omega/venv/local/lib/python2.7/site-packages/django/core/paginator.py", line 57, in page
number = self.validate_number(number)
File "/home/omega/venv/local/lib/python2.7/site-packages/django/core/paginator.py", line 46, in validate_number
if number > self.num_pages:
File "/home/omega/venv/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/omega/venv/local/lib/python2.7/site-packages/django/core/paginator.py", line 91, in num_pages
if self.count == 0 and not self.allow_empty_first_page:
File "/home/omega/venv/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/omega/venv/local/lib/python2.7/site-packages/django/core/paginator.py", line 84, in count
return len(self.object_list)
TypeError: object of type 'RawQuerySet' has no len()
结束这是html的一部分,我有我的分页代码。 tables_list.html
def addview(request, table_id):
table_name = Crawledtables.objects.get(id=table_id)
tbl_details = "SELECT * FROM " + table_name.name
tbl_detail = AllTables.objects.raw(tbl_details)
paginator = Paginator(tbl_detail, 25)
page = request.GET.get('page')
try:
details = paginator.page(page)
except PageNotAnInteger:
details = paginator.page(1)
except EmptyPage:
details = paginator.page(paginator.num_pages)
crawled_tables = AllTablesFilter(request.GET, queryset=tbl_detail)
return render(request, 'tables/table_list.html', {'tbl_name': table_name,
'details': tbl_detail,
'filter': crawled_tables,
'detail_page': details})
是因为我使用了objects.raw()?
提前感谢您的帮助
答案 0 :(得分:1)
更改此行
paginator = Paginator(tbl_detail, 25)
到
paginator = Paginator((list(tbl_detail)), 25)