當我單擊按鈕時,我總是得到方法 GET 而不是 post:任何想法?謝謝!
<body>
<form action="/reset" type="POST">
{% csrf_token %}
<h3>Random Word (attempt # {{request.session.counter}})</h3>
<div>
<h1>{{request.session.rword}}</h1>
</div>
<label for="title">Title</label>
<input type="text" name="title" id="">
<button type="submit">Generate</button>
</form>
uj5u.com熱心網友回復:
請求的型別由method="…屬性指定,因此:
<form action="/reset" method="POST">
…
</form>
uj5u.com熱心網友回復:
<body>
<form action="/reset" method="POST">
{% csrf_token %}
<h3>Random Word (attempt # {{request.session.counter}})</h3>
<div>
<h1>{{request.session.rword}}</h1>
</div>
<label for="title">Title</label>
<input type="text" name="title" id="">
<button type="submit">Generate</button>
</form>
uj5u.com熱心網友回復:
由于您使用了type屬性,而不是method屬性(這是正確的),因此您的代碼無法正常作業。要更改此設定,您必須將 更改type為method。此外,對于表單的操作部分,我認為最好使用 Django url 模式,例如,{% url 'reset' %}而不是撰寫/reset.
<body>
<!-- So in this line, I changed the action, as well as the type to method, make sure to put the actual url pattern of the /reset page rather than what I put -->
<form action="{% url 'reset' %}" method="POST">
{% csrf_token %}
<h3>Random Word (attempt # {{request.session.counter}})</h3>
<div>
<h1>{{request.session.rword}}</h1>
</div>
<label for="title">Title</label>
<input type="text" name="title" id="">
<button type="submit">Generate</button>
</form>
<body>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/343436.html
