use*_*491 5 django django-templates django-filter django-crispy-forms
具体来说,使用django-filter文档中的示例模板:
{% extends "base.html" %}
{% block content %}
<form action="" method="get">
{{ filter.form.as_p }}
<input type="submit" />
</form>
{% for obj in filter %}
{{ obj.name }} - ${{ obj.price }}<br />
{% endfor %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
其他人知道如何使酥脆的形式起作用吗?
插入以下内容可使表单很好地呈现,但我无法使其真正起作用。
{% crispy filter.form %}
Run Code Online (Sandbox Code Playgroud)
想通了-太容易了。我发誓早些时候尝试过这种方法,尽管我一定做错了。很抱歉问这样一个简单的问题。
答案是改变:
{{ filter.form.as_p }}
Run Code Online (Sandbox Code Playgroud)
至:
{{ filter.form|crispy }}
Run Code Online (Sandbox Code Playgroud)
我只需要添加加载脆标签。
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<form action="" method="get">
{{ filter.form|crispy }}
<input type="submit" />
</form>
{% for obj in filter %}
{{ obj.name }} - ${{ obj.price }}<br />
{% endfor %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)