如何使用 django 创建"sort by"下拉输入?



尝试使用django构建Web应用程序,但在找到如何为用户创建下拉输入以对页面上的项目进行排序方面遇到了挑战。

具有过滤形式:

<form>
{{filter.form|crispy}}
<button type="submit">submit</button>
</form>

有类似的东西吗?

<form>
{{sort.form}}
</form>
<form action="">
<select name="sort_name">
<option value="-price">low to high</option>
</form>

在视图中:

def funName(request):
ordering = request.GET['sort_name']

最新更新