Discuss / Python / 翻不了页。。。怎么办

翻不了页。。。怎么办

Topic source

alienation

#1 Created at ... [Delete] [Delete and Lock User]

不知道怎么用__base__里的这段被注释掉的翻页语句

{% macro pagination(url, page) %}
    <ul class="uk-pagination">
        {% if page.has_previous %}
            <li><a href="{{ url }}{{ page.page_index - 1 }}"><i class="uk-icon-angle-double-left"></i></a></li>
        {% else %}
            <li class="uk-disabled"><span><i class="uk-icon-angle-double-left"></i></span></li>
        {% endif %}
            <li class="uk-active"><span>{{ page.page_index }}</span></li>
        {% if page.has_next %}
            <li><a href="{{ url }}{{ page.page_index + 1 }}"><i class="uk-icon-angle-double-right"></i></a></li>
        {% else %}
            <li class="uk-disabled"><span><i class="uk-icon-angle-double-right"></i></span></li>
        {% endif %}
    </ul>
{% endmacro %}

所有有列表的url都没法翻页,看了下html有关pagination的dom只有

{{ pagination('/?page=', page) }}

或者

<div v-component\="pagination" v-with\="page"\></div\>

相应的handler中page参数是由Page对象定义,顺便修了下代码

@get('/')
async def index(*, page='1'):
    page_index = get_page_index(page)
    num = await Blog.findNumber('count(id)')
    page = Page(num, page_index)
    if num == 0:
        blogs = []
    else:
        blogs = await Blog.findAll(orderBy='created_at desc', limit=(page.offset, page.limit))
    return {
        '__template__': 'blogs.html',
        'page': page,
        'blogs': blogs,
    }

alienation

#2 Created at ... [Delete] [Delete and Lock User]

火速看了遍vue和jinja的macro,可算是搞懂了,是page对象缺了has_previous和has_next两个布尔属性

根据当前页面号码判断出布尔值就可以了


  • 1

Reply