簡體   English   中英

Django POST以形式顯示,但沒有進入下一個視圖

[英]Django POST shows in form, but doesn't come through to the next view

我有一個簡單的表格,例如:

    <form action = "{% url 'endresult' %}" form method = "POST">
          {% csrf_token %}
        <div class="well">
          <h4 style="margin-top: 0"><strong> Student Details </strong></h4>
          <div class="row">
            <div class="form-group col-md-4">
              <label/> Student ID
              <input class="form-control" type="text" name = "studentpost" placeholder= "{{student.studentid}}" readonly>
            </div>
     </form>
</div>

學生證確實會顯示在我的表格中,但是當我嘗試從endresult結果中獲取結果時,它會顯示為空白,如果我嘗試給studentid endresult打電話,我什么也沒得到。 為什么是這樣?

def endresult(request):
    postedstudent = request.POST.get('studentpost')
    print(f"postedstudent : {postedstudent }")
    studentid = request.POST.get('student.studentid')
    print(f"studentid : {studentid }")
return render(request, 'submitted.html')

這是我的輸出:

postedstudent:
學生編號:無

占位符值就是占位符。 它們將替換為在字段中輸入的任何內容,並且不會通過表單提交。

如果希望預先填充值以便提交,則應改用value屬性。

我不知道為什么您認為request.POST.get('student.studentid')會給出一個值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM