1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Django フォームセットでPOSTでの取得の仕方がわからない。

Last updated at Posted at 2019-10-23

11111111111111111111.png

form.py
class 案内Form(forms.Form):    
    会社別=forms.CharField(required=False,max_length=3,widget=forms.TextInput(attrs={'class': "form-control"}))
views.py
class 案内View(TemplateView):  
    def __init__(self):
        案内FormSet=formset_factory(案内Form,extra=6)
        #buf=フォーム初期値入力
        buf={'会社別':1,'会社別':2,'会社別':3,'会社別':4,・・・}
        formset =案内FormSet(initial=buf)
        self.params = {
            'guide':formset,                       
        }
    def post(self, request):           
        formset = 案内FormSet(request.POST)
        #print(formset)でエラーが出る。
        print(formset)        
        return render(request, 'jw/guide.html', self.params)
guide.html
 <tbody>
・・・・・省略・・・・ 
<tr>
  <td>1</td>
  <td><input type="text" name="form-0-会社別" value="1" class="form-control" maxlength="3" id="id_form-0-会社別"></td>
  <td>
    <ruby>
      <rb>十九</rb>
      <rt>ジュウク</rt>
       <rb>太郎</rb>
      <rt>タロウ</rt>
    </ruby>
  </td>
  <td>10/04</td>
  <td>新規</td>
  <td>SN-1F</td>
  <td>提出物</td>
  <td>入金</td>
  <td></td>
  <td>株式会社ジューク</td>
</tr>
<tr>
  <td>2</td>
  <td><input type="text" name="form-1-会社別" value="2" class="form-control" maxlength="3" id="id_form-1-会社別"></td>
  <td>
    <ruby>
      <rb>山崎</rb>
      <rt>ヤマサキ</rt>
       <rb>太郎</rb>
      <rt>タロウ</rt>
    </ruby>
  </td>
  <td>10/04</td>
  <td>新規</td>
  <td>SN-1F</td>
  <td>提出物</td>
  <td>入金</td>
  <td></td>
  <td>株式会社ヤマダ</td>
</tr>
・・・・・省略・・・・              
</tbody>
          
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?