Python Flask-WTF - use same form template for add and edit operations

前端 未结 2 1051
一整个雨季
一整个雨季 2021-01-31 21:59

I\'m just getting started with Flask / Flask-WTF / SQLAlchemy, and most example CRUD code I see shows separate templates for adding / editing. It seems repetitive to have two te

2条回答
  •  一向
    一向 (楼主)
    2021-01-31 22:41

    The simplest way I tried to overcome this issue was to not include the SubmitField in the form (BookForm). We can pass the form submit value as variable to the form, e.g submit='Update' in the edit_book route and submit='Add Book'.

    In the route, populate the fields with the details related to the book if the post method is 'GET'

提交回复
热议问题