如何獲取由Django中的表單提交的所有選項,這是我使用的表單。如何獲取表單提交的所有選項
{% extends 'quiz/base.html' %}
{% block content%}
<h1>You are at quiz page</h1>
<form action="{% url 'quiz:process_data' %}" method="post">
{% csrf_token %}
{% for question in question_set %}
<h3>{{question.id}}.{{question.question_text }}</h3>
{% for option in question.options_set.all %}
<input type="radio" name="choice{{question.id}}" value="{{ option.options}}" > {{option.options}}<br>
{% endfor %}
{% endfor %}
<input type="Submit" name="Submit">
</form>
{% endblock%}
我試過selected_choice=request.POST
,但得到這個作爲輸出csrfmiddlewaretokenchoice1Submitchoice3
。我該如何解決這個問題?謝謝
Request.POST是一本字典。所以只是'request.POST.get('form_field_name')' –
請張貼您的form.py. –