Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 将数据从一个视图传递到另一个django_Html_Django_Forms - Fatal编程技术网

Html 将数据从一个视图传递到另一个django

Html 将数据从一个视图传递到另一个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

我的应用程序中有两个视图

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_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}