почему не отправляеться value из button?
<form method="post" action="{% url 'base' %}" id="sorted-games">
{% csrf_token %}
<div class="tab">
{% for i in game_sorted %}
<button value="{{ i.name }}" id="games_sorted" type="button" name="games_sorted_name" class="tablinks">{{ i.name }}</button>
{% endfor %}
</div>
</form>
<script type="text/javascript">
$(function(){
$('#sorted-games').click(function(e){
e.preventDefault();
var data = $(this).serialize();
$.ajax({
type: "POST",
url: "{% url 'base' %}",
data: data,
success: function(result){
$('#result-games-sorted').html(result);
}
});
});
});
</script>
utils.py
class ContextBase(ListView):
def post(self, request):
if "games_sorted_name" in self.request.POST:
name = self.request.POST.get("games_sorted_name")
print(name)
queryset = Games.objects.all().order_by('name')
list_game_id_num = []
for i in queryset:
if name == f'{i}'[0]:
list_game_id_num.append(i.id_num)
context = {
'games': Games.objects.filter(id_num__in=list_game_id_num).order_by('name'),
}
return render(request, 'result_sorted_games.html', context)
print(name) = None