如何在django泛型listView中檢索表單搜索參數。我的網址是:Django:如何在django泛型列表中檢索表單搜索參數查看
url(r'postsearch$', views.PostsList.as_view(), name='postsearch'),
我的通用列表視圖是:
class PostsList(generic.ListView):
model = Post
template_name = 'posts/post_list.html'
def get_queryset(self):
localisation = #how to get location
discipline = #how to get discipline
return Post.objects.filter(.......)
,我的形式是:
<form class="form-inline text-center" action="{% url 'posts:postsearch' %}" id="form-searchLessons" method="get">
<div class="form-group">
<input type="text" class="form-control" id="typeCours" list="matieres" placeholder="Matieres: e.g. Math, Physique,.." name="discipline">
<datalist id="matieres">
<option value="value1">
<option value="value2">
</datalist>
</div>
<div class="form-group">
<input type="text" class="form-control" id="Localisation" placeholder="Lieu: Bousaada, Douaouda,.."
name="localisation" onFocus="geolocate()">
</div>
<button type="submit" class="btn btn-default" id="btn-getLessons">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span> Trouver !
</button>
</form>
我想根據應用過濾器來獲取帖子在搜索字段中引入的lacalisation和matieres(在表格中)
它不承認關鍵字的本地化和紀律,所以我用json來獲取參數 – A2maridz