使用下拉列表中的名称



我想在请求POST查询中使用下拉菜单,但我无法定义下拉菜单选项的名称,我该如何做到这一点?是否有机会根据这个查询中的POST值做其他事情?

my ex. view;

def list(request):
if 'Storefront' in request.POST:
filtre=Alarmlar.objects.filter( Ekip__contains="Storefront" )
elif 'CAC' in request.POST:
filtre=Alarmlar.objects.filter ( Ekip__contains="Cac")
else:
filtre=Alarmlar.objects.all()
members_list=filtre
paginator = Paginator(members_list, 100)
page = request.GET.get('page')
try:
members = paginator.page(page)
except PageNotAnInteger:
members = paginator.page(1)
except EmptyPage:
members = paginator.page(paginator.num_pages)
return render(request, 'list.html', {'members': members}) 

html;

<select class="form-control" id="adsoyad" name="adsoyad" style="text-align:center" required>
<option value="" disabled selected >Choose...</option>
<option value="all">ALL</option>
<option value="Cac">Cac</option>
<option value="Storefront">Storefront</option>
</select>

名称为adsoyad,因为您指定的是<select name="adsoyad" …>。因此,您可以使用:

进行过滤
def list(request):
data = request.POST.get('adsoyad')
ifdata == 'Storefront':
filtre=Alarmlar.objects.filter( Ekip__contains="Storefront" )
elifdata == 'Cac':
filtre=Alarmlar.objects.filter ( Ekip__contains="Cac")
else:
filtre=Alarmlar.objects.all()
members_list=filtre
paginator = Paginator(members_list, 100)
page = request.GET.get('page')
try:
members = paginator.page(page)
except PageNotAnInteger:
members = paginator.page(1)
except EmptyPage:
members = paginator.page(paginator.num_pages)
return render(request, 'list.html', {'members': members})

相关内容

  • 没有找到相关文章

最新更新