What does Python return ''
means in the follow code?
@register.simple_tag(takes_context=True)
def paginate(context, object_list, page_count):
left = 3
right = 3
paginator = Paginator(object_list, page_count)
page = context['request'].GET.get('page')
try:
object_list = paginator.page(page)
context['current_page'] = int(page)
pages = get_left(context['current_page'], left, paginator.num_pages) + get_right(context['current_page'], right,
paginator.num_pages)
except PageNotAnInteger:
object_list = paginator.page(1)
context['current_page'] = 1
pages = get_right(context['current_page'], right, paginator.num_pages)
except EmptyPage:
object_list = paginator.page(paginator.num_pages)
context['current_page'] = paginator.num_pages
pages = get_left(context['current_page'], left, paginator.num_pages)
context['article_list'] = object_list
context['pages'] = pages
context['last_page'] = paginator.num_pages
context['first_page'] = 1
try:
context['pages_first'] = pages[0]
context['pages_last'] = pages[-1] + 1
except IndexError:
context['pages_first'] = 1
context['pages_last'] = 2
return ''
return ''
is simply returning an empty string.
So with your function, if you did
example = paginate(context, object_list, page_count)
example
would be a string, but one with nothing in it.
Similar to how name = ''
is an empty variable.
If after assigning that to name, you tried print(name)
, you would simply get (if you were using a console on Linux and possibly windows) as new line printed, nothing more, possibly nothing less.