[英]Passing button name from name to function - Django
I'm looking for help.我在寻求帮助。 I'm newbie in Django, python.我是 Django 的新手,python。
I'm want to pass name of clicked button to function in views and then use it as a filter.我想传递单击按钮的名称以在视图中运行,然后将其用作过滤器。
This is html:这是 html:
<tr>
<td><a class="btn btn-primary" href="{% url 'display_ph' %}" role="button" method="post">{{ item.nazwa }}</a></td>
<td>{{ item.ulica }}</td>
<td>{{ item.miejscowosc }}</td>
<td>{{ item.kod_pocztowy }}</td>
</tbody>
And I want to take "nazwa" and pass it to function:我想把“nazwa”传递给函数:
def display_ph(request, nazwa):
filter = request.GET.get('nazwa', False)
items = Phandlowy.objects.filter(firma=filter)
context = {
'items': items,
}
return render(request, 'ph.html', context)
I don't now if it is possible with this button.如果可以使用此按钮,我现在不会。 Thank you for looking at this issue.感谢您查看此问题。
You can pass it as query parameter:您可以将其作为查询参数传递:
<a href="{% url 'display_ph' %}?nazwa={{item.nazwa}}">
And inside your view:在你的观点中:
def display_ph(request):
filter = request.GET.get('nazwa', False)
items = Phandlowy.objects.filter(firma=filter)
context = {
'items': items,
}
return render(request, 'ph.html', context)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.