繁体   English   中英

表单输入未在 Request.POST 中显示

[英]Form Input Not showing in Request.POST

我正在尝试创建一个使用 Dropzone 的表单,但我需要添加另一个输入。 问题是当我尝试从服务器访问其他输入时,服务器找不到它。

这是我有 atm 的 html 代码

{% load static %}

{% block content %}


<div class="pt-3 pb-2 mb-3 border-bottom">

        <form action="#" method="POST" class="dropzone dz" id="dropzone" name="dropzone" >
            {% csrf_token %}
                <div class="fallback" >
                    <input name="file" type="file" multiple />
                    <input type='text' name='fullname' value='what ever you need to get in backend'>
                </div>
        </form>


        <button type="button" class="btn btn-outline-success" id='uploadfiles' value='Submit' >Submit</button>
            <span data-feather="save"></span>
            Submit
        </button>-->

</div>


<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/jq-3.3.1/jszip-2.5.0/dt-1.10.20/b-1.6.1/b-html5-1.6.1/b-print-1.6.1/datatables.min.css"/>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/jq-3.3.1/jszip-2.5.0/dt-1.10.20/b-1.6.1/b-html5-1.6.1/b-print-1.6.1/datatables.min.js"></script>

<script type = "text/javascript">

    $('#dropzone').submit(function() {
      console.log('Hello');
    });



    Dropzone.options.dropzone =
             {
                autoProcessQueue: false,
                maxFiles: 1,
                acceptedFiles: ".xlsx",
                addRemoveLinks: true,

                  init: function() {
                    var submitButton = document.querySelector("#uploadfiles")
                        myDropzone = this; // closure

                    submitButton.addEventListener("click", function() {
                      var a = document.getElementById('pymt_date').value
                      var CurrentDate = new Date();
                      GivenDate = new Date(a);
                      if (a == null || a == ""){
                        alert("Please Enter Payment Date");
                        return false;
                      }
                      else if (GivenDate < CurrentDate) {
                        alert("Payment Date Must be greater than today");
                        return false;
                      }
                      else {
                          console.log(document.getElementById('pymt_date').value);
                          myDropzone.processQueue();
                          setTimeout(function() {
                                location.reload();
                            }, 5000);
                          }
                       // Tell Dropzone to process all queued files.
                    });
                  }
            };

</script>

你能帮我看看是什么问题吗? 当我尝试打印 request.POST 以获取输入 name="fullname" 的值时,我得到的只是 csrf 令牌,仅此而已。

首先,您的提交按钮不在表单中。 Imo 应该在里面,按钮的类型应该是“提交”而不是“按钮”。 另一件事是不清楚你想在哪里访问 request.POST。 在 Django 视图中? 所以在表单中 make: enctype="multipart/form-data 正如 Willem Van Onsem 所说。再次在表单中放置提交按钮。所以你将能够在视图中处理 POST 请求。并检查你的代码有一些错误 - 两次关闭,提交等。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM