python 我的提交按钮没有调用POST函数,我不知道为什么

bq3bfh9z  于 2023-03-28  发布在  Python
关注(0)|答案(1)|浏览(97)

这是我的page2.html文件

<form method="post" action="/" class="search-div justify-center align-center text-center form" id="form-change" >
        {% csrf_token %}
        <label for="contact-owner">Do you want to check an Email or Phone number?</label>
        <br>
        <br>
        <select name="--select--" id="contact-type" required >
            <option value="">--Select--</option>
            <option value="email" id="mail">Email</option>
            <option value="phone" id="phn">Phone No.</option>
            <option value="sms-o" id="sms">SMS</option>
        </select>
        <br>
        <br>
        <label for="contact">Enter Contact : </label>
        <br>
        <input type="email" class="search" id="contact_number" required>
        <br><br>
        <div id="mail-details">
            <label for="subject">Enter Subject of Email : </label>
            <br>
            <input type="text" class="search" id="subject" name="subject" required="required ">
            <br><br>
            <label for="mail-body">Enter Body of Email : </label>
            <br>
            <input type="text" class="search" id="mail-body" name="mail-body" required="required ">
            <br><br>
        </div>
        <div id="sms-details">
            <label for="sms">Enter SMS recieved : </label>
            <br>
            <input type="text" class="search" id="sms" name="sms" required="required ">
        <br><br>
        </div>
        <div id="after-sub" class="active">
            <label for="spam-check">Spam</label><br>
            <input type="text" id="spam-check" required readonly>
            <br><br>
            <label for="risk-score">Risk Score</label><br>
            <input type="text" id="risk-score" readonly>
            <br>
        </div>
        <button type="submit" id="sub">Submit</button>
    </form>

这是我的urls.py

def page2(request):

    if request.method == "POST":
        print("Test2")
        return render(request, 'page2.html')

    print("TEST1")
    return render(request, 'page2.html')

只有TEST1被打印。我无法输入我的请求。method=='POST' block.
我已经尝试改变按钮类型,并检查大小写敏感性的机会,这是我的错误。

5anewei6

5anewei61#

调整你的表单,特别是标签需要一个name=属性,例如:
然后再次测试。

相关问题