1

私はDjangoでかなり新しいです。私は何かが見落とされていると思います。私は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> 

以下のように私は

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 

方法上の任意のヘルプを次のように私は私がやっている選択したラジオボタンの値にアクセスできるようにしたい動的に投入していますフォームを持っていますクリックされたラジオボタンの価値を得ることは、高度にリンケージされます。

答えて

0

ラジオボタンから直接データが取り込まれるため、データを消去する必要はありません。selected_choice = request.POST['choice'])などのように試してみてください。これが役立ちます。

関連する問題