Pre-populate HTML form table from database using Django

前端 未结 3 1356
醉话见心
醉话见心 2021-02-11 02:26

I have a class-based view (IndexView at views.py) that shows a table with all the data stored in the database. This view is rendered in index.html<

3条回答
  •  伪装坚强ぢ
    2021-02-11 03:05

    There are multiple ways of loading data into forms, as far as I know:

    • In views.py

    You are using FormView CBV which has a func called get_intial:

        def get_initial(self):
            initial = super().get_initial()
            initial[''] = 
            return initial
    
    • In forms.py

    You can override the init func:

        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.fields[''].initial = 
    

提交回复
热议问题