これは非常に簡単です。ピン属性を持つオブジェクトのデータベースがあります。
使用事例
- ユーザー入力 4 桁のピン
- ピン番号が一致するオブジェクトを表示します
ジャンゴでこれを達成する最も簡単な方法は何ですか?
index.html
<form action="/polls/" method="post">
{% csrf_token %}
<p>
<label for="pin">Enter group pin:</label>
<input id="pin" type="text" name="pin" maxlength="4" />
<input type="submit" value="View Polls" />
</p>
</form>
現在、ハードコードされています
{% for poll in latest_poll_list %}
{% if poll.pin == "1234" %}
<ul class="poll-list">
<li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a> - {{poll.pin}}</li>
</ul>
{% endif %}
{% endfor %}