Django Paginator不能超出第一页 [英] Django Paginator not working beyond first page

查看:131
本文介绍了Django Paginator不能超出第一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如标题所述,当我点击进入第一个页面之后,我的分页符不会显示任何内容。
首先,让我一般来描述我的页面:

它的功能是从用户那里获取一个请求输入,指定他希望看到一堆通话记录的周期间隔与其他过滤器(这很重要)。所以本质上从请求开始和结束日期,我用它来过滤我的对象。
page2的链接类似于:localhost:8000 /?page = 2,并重定向到我现有的页面,但没有任何数据。现在很明显,到下一页的链接应该包括其他参数,如start_date = xxxx-xx-xx,否则它不会工作。

As mentioned in the title, my paginator doesn't show anything when I click to go to a page beyond the first. First, let me describe my page in general:
Its function is to get a request input from the user specifying the period interval from which he wants to see a bunch of "call records" along with other filters (this is important). So essentially there's a start and end date from the request and I use it to filter my objects. The link to "page2" is something like: "localhost:8000/?page=2" and redirects to my existing page but without any data. It's obvious now that the link to the next page should include the other parameters such as start_date=xxxx-xx-xx, or else it wouldn't work.

这里是部分我的view.py和我拿出了很多的线条,使其简洁,代码运行正常:

Here's part of my view.py and I took out a lot of lines to make it brief, the code runs fine:

if request.GET:   
    filter_form = ReportFilterForm(request.GET)
    if filter_form.is_valid():
        start = filter_form.cleaned_data["start_date"]
        end = filter_form.cleaned_data["end_date"]  

        #a bunch of omitted lines that use the form to filter
        paginator = Paginator(queryset, 100)

        try:
            page = int(request.GET.get('page', '1'))
        except ValueError:
            page = 1
        try:
            call_logs = paginator.page(page)
        except (EmptyPage, InvalidPage):
            call_logs = paginator.page(paginator.num_pages)
else:
    filter_form = ReportFilterForm()
return render_to_response('xxxx.html', 
                          {'queryset': queryset,
                           'filter_form': filter_form,
                           'call_logs': call_logs, 
                           })

我的模板xxxx.html只是分页部分,这是非常标准的,取自文档:

My template xxxx.html, just the paginator section, which is pretty standard, taken from the documentation:

                {% if call_logs.paginator.num_pages %}
                <div class="pagination">
                    <span class="step-links">
                        {% if call_logs.has_previous %}
                            <a href="**{{ SOME_MAGIC_TEMPLATE_VARIABLE_THAT_GETS_CURRENT_ABSOLUTE_URL}}**&?page={{ call_logs.previous_page_number }}"><<</a>
                        {% endif %}
                        <span class="current">
                            Page {{ call_logs.number }} of {{ call_logs.paginator.num_pages }}
                        </span>
                                {% if call_logs.has_next %}
                                      <a href=" **{{ SOME_MAGIC_TEMPLATE_VARIABLE_THAT_GETS_CURRENT_ABSOLUTE_URL}}**&page={{ call_logs.next_page_number }}">>></a>
                                {% endif %}
                    </span>
                </div>
                {% endif %}

我的问题是如何获取当前的窗口URL django模板,而不是javascript?
谢谢。

My question is how do I get the current window URL using django templates and not javascript? Thank you.

推荐答案

如果我正确理解您,可以从请求对象添加上下文的完整路径:

You could add the full path to the context from the request object if I understand you correctly:

return render_to_response('xxxx.html', 
                          {'queryset': queryset,
                           'filter_form': filter_form,
                           'call_logs': call_logs,,
                           'magic_url': request.get_full_path(),
                           })

这篇关于Django Paginator不能超出第一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆