访问模板中的url参数

时间:2018-11-30 06:54:05

标签: django django-templates django-admin

我覆盖了SimpleListFilter 最后,我在模板中创建表格

我的网站也具有搜索功能,因此,如果我进行搜索,则网址会变成

http://url/corelog/?q=nda

,当我使用列表过滤器时,网址看起来像

http://url/corelog/?scoreRange=0.2-1

它会从我的网址参数中删除搜索字词

我想成为

这样的网址
http://url/corelog/?q=nda&scoreRange=0.2-1

所以我试图使用隐藏字段来保留这些值,但是这并没有达到我的预期。

我正在使用context_processors。尝试像模板中的{{request.GET.q}}一样访问它们并没有给我任何东西。 如何在模板中获取这些url参数

admin.py

class RangeFilter(admin.SimpleListFilter):

    title = 'Score'
    parameter_name = 'scoreRange'
    template = 'admin/corelog/input_filter.html'
    def lookups(self, request, model_admin):
        return (
            ('Yes', ''),
        )

    def queryset(self, request, queryset):
    ..
        return queryset

input_filter.html

{% block content %}
<h3>{% blocktrans with filter_title=title %} By {{ filter_title }} {% endblocktrans %}</h3>

<ul>
    <li>
        <form>
            <p>
                {% for key, value in request.GET.items %}
                    <input type="text" name="{{ key }}" value="{{ value }}">
                {% endfor %}

                <label >「スライダーで下限と上限を設定後、下のボタンを押してください。」</label>
                <div id="slider-range"></div>
                <label style="font-weight: bold;">検索:</label>

                <input type="submit" id="scoreRange" name="scoreRange">
            </p>
        </form>

    </li>
</ul>
{% endblock %}

0 个答案:

没有答案
相关问题