Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django中只返回最后一个标签输入值_Django_Python 3.x_Django Forms_Django Templates_Django Views - Fatal编程技术网

Django中只返回最后一个标签输入值

Django中只返回最后一个标签输入值,django,python-3.x,django-forms,django-templates,django-views,Django,Python 3.x,Django Forms,Django Templates,Django Views,我刚到Django,我想我忽略了一些事情。我有一个动态填充的表单,如下所示 <form method="post"> {% csrf_token %} {{ profile.days }}//Only prints last radio button value {% for period, value in profile.periods.items %}

我刚到Django,我想我忽略了一些事情。我有一个动态填充的表单,如下所示

<form method="post">
                {% csrf_token %}
                {{ profile.days }}//Only prints last radio button value
                {% for period, value in profile.periods.items %}

                <h2>{{ period }} Reports</h2>
                <label>
                    <input name="days" value={{ value }} type="hidden">
                    <input
                            name="reports_allowed"
                            type="radio"
                            {% if profile.reports_allowed and profile.days == value %} checked {% endif %}>
                    Each {{ value }} send me a summary of my checks
                </label>
                {% endfor %}
                <button
                        name="update_reports_allowed"
                        type="submit"
                        class="btn btn-default pull-right">Save</button>

            </form>

任何关于如何获取单击的单选按钮的值的帮助都将非常有用。

由于单选按钮是直接填充的,所以不需要从中清除数据,请尝试类似于
selected\u choice=request.POST['choice'])
,希望这有帮助。

由于单选按钮是直接填充的,所以不需要从中清除数据,尝试类似于
selected\u choice=request.POST['choice'])
,希望这有帮助

form = ReportSettingsForm(request.POST)
        if form.is_valid():
            print(form.cleaned_data)
            days = form.cleaned_data["days"]
            print(days)# Prints only the last value always