Answer the question
In order to leave comments, you need to log in
How to generate a form on the go?
Idea such:
To take from a DB headings of columns and on the move for different users to generate forms.
For example:
There is a class that pulls out the headings of the columns of a table in the form of a list
class DbFields: # returns col-names from base for rendering forms
@staticmethod
def get_col_names(name): # name - table name
a = 'select * from ' + name
cursor.execute(a)
return [member[0] for member in cursor.description]
class UserInput(FlaskForm):
@staticmethod
def form_render(table):
fields = []
names = DbFields.get_col_names(table)
for i in range(len(names)):
f = StringField(names[i], validators=[DataRequired()])
fields.append(f)
return fields
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question