Html 将数据从一个视图传递到另一个django
我的应用程序中有两个视图 Views.pyHtml 将数据从一个视图传递到另一个django,html,django,forms,Html,Django,Forms,我的应用程序中有两个视图 Views.py def selectwarehouse(request): z = Warehouse.objects.all() return render(request, 'packsapp/employee/selectwarehouse.html', {'z': z}) def warehouse_details(request): queryset = AllotmentDocket.objects.filter(send_fro
def selectwarehouse(request):
z = Warehouse.objects.all()
return render(request, 'packsapp/employee/selectwarehouse.html', {'z': z})
def warehouse_details(request):
queryset = AllotmentDocket.objects.filter(send_from_warehouse = #dynamic(from the selectwarehouse.html))
return render(request, 'packsapp/employee/allotwarehousedetails.html', {'query': queryset})
selectwarehouse.html
{% block content %}
<label>Select Warehouse<label>
<select id="the-id">
{% for i in z %}
<option value="{{ i }}">{{ i }}</option>
{% endfor %}
<form method="post" novalidate>
{% csrf_token %}
<a href="{% url 'employee:warehouse_details' %}" class="btn btn-outline-secondary" role="button">Proceed</a>
<a href="{% url 'employee:products_table' %}" class="btn btn-outline-secondary" role="button">Nevermind</a>
</form>
</select>
{% endblock %}
我希望当一个人从下拉列表中选择“仓库”并单击“继续”时,他应该将该值传递给def Warehouse\u details
,并将该值传递给分配查询集。我如何才能做到这一点?将“继续”作为隐藏输入
模板
检查这是否有效
尝试打印查询集并查看输出内容。您需要在
中指定action=“url/to/warehouse\u details/view”
。您的
应该是form@YevhenKuzmovych而不是href,我应该将其指向仓库_详细信息视图?是的,我想是这样。否则,按钮只会将您重定向到employee:warehouse\u details
URL,并带有GET
,而不是POST
,并且没有来自
s的任何信息。@YevhenKuzmovych我对django的模板不熟悉,您能告诉我怎么做吗?您的html表单是由内而外的,它不会,我刚刚看到输入之前有“endfor”,这就是为什么它不知道什么是“i”,在我编辑代码检查之后使用“endfor”,现在你还没有在表单标签中添加任何操作,添加它,否则它将无法工作,否则给你的回购我会解决它。我不能给你回购,抱歉,请帮助我将操作添加到“继续”按钮
path('select-warehouse/', selectwarehouse, name='select_warehouse'),
path('warehouse-details/', warehouse_details, name='warehouse_details'),
{% block content %}
<label>Select Warehouse<label>
<select id="the-id">
{% for i in z %}
<option value="{{ i }}">{{ i }}</option>
<form method="post" novalidate>
{% csrf_token %}
<input type="hidden" name="object_id" value="{{ i.id }}">
<input class="btn btn-outline-secondary" name="Proceed" type="submit"
value="Proceed">
<a href="{% url 'employee:products_table' %}" class="btn btn-outline-
secondary" role="button">Nevermind</a>
</form>
{% endfor %}
</select>
{% endblock %}
def selectwarehouse(request):
z = Warehouse.objects.all()
return render(request, 'packsapp/employee/selectwarehouse.html', {'z': z})
def warehouse_details(request):
queryset = AllotmentDocket.objects.get(id=request.POST.get('object_id'))
//Now to access the element in queryset write (queryset.'attribute name')
return render(request, 'packsapp/employee/allotwarehousedetails.html', {'query':
queryset}