Python wtforms.Form() Examples
The following are 30
code examples of wtforms.Form().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
wtforms
, or try the search function
.
Example #1
Source File: app.py From myflaskapp with MIT License | 6 votes |
def dashboard(): # Create cursor cur = mysql.connection.cursor() # Get articles #result = cur.execute("SELECT * FROM articles") # Show articles only from the user logged in result = cur.execute("SELECT * FROM articles WHERE author = %s", [session['username']]) articles = cur.fetchall() if result > 0: return render_template('dashboard.html', articles=articles) else: msg = 'No Articles Found' return render_template('dashboard.html', msg=msg) # Close connection cur.close() # Article Form Class
Example #2
Source File: user_controller.py From codecat with GNU General Public License v3.0 | 6 votes |
def List_table_users(): if check_auth() == False: return redirect("front/auth") class TheForm(Form): name = TextField('id:', validators=[validators.required(), validators.Length(min=1, max=9)]) class Meta: csrf = True csrf_class = tokenform.Ice_CSRF form = TheForm( request.form, meta={'csrf_context': request.remote_addr } ) obj=user_rest_api obj=obj.rest_call("","") obj.token=session['userkey'] obj.List_Users() users=[] for rows in obj.json_output: users.append({"id": rows[0],"name": rows[1],"email": rows[2],"owner": rows[3],"date": rows[4]}) return render_template('user_forms/user_list.html',form=form, users=users, title="Table of Users")
Example #3
Source File: rule_controller.py From codecat with GNU General Public License v3.0 | 6 votes |
def List_table_rules(): class TheForm(Form): rule = TextField('id:', validators=[validators.required(), validators.Length(min=1, max=32)]) class Meta: csrf = True csrf_class = tokenform.Ice_CSRF form = TheForm( request.form, meta={'csrf_context': request.remote_addr } ) if user_controller.check_auth() == False: return redirect("front/auth") obj=rule_rest_api obj=obj.rest_call("","") obj.token=session['userkey'] obj.List_rules() rules=[] for rows in obj.json_output: rules.append(rows) return render_template('rule_forms/rule_list.html',form=form, rules=rules, title="Table of rules")
Example #4
Source File: forms.py From marvin with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, *args, **kwargs): ''' Initializes a Marvin Form Generates all the WTForms from the SQLAlchemy ModelClasses defined in the MaNGA DB. _param_form_lookup = dictionary of all modelclass parameters of form {'SQLalchemy ModelClass parameter name': WTForm Class} ''' self._release = kwargs.get('release', config.release) self.verbose = kwargs.get('verbose', False) if marvindb: self._modelclasses = FuzzyDict(marvindb.buildUberClassDict(release=self._release)) self._param_form_lookup = ParamFormLookupDict(**kwargs) self._param_fxn_lookup = ParamFxnLookupDict() self._paramtree = tree() self._generateFormClasses(self._modelclasses) self._generateFxns() self.SearchForm = SearchForm self._cleanParams(**kwargs)
Example #5
Source File: forms.py From marvin with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _generateFormClasses(self, classes): ''' Loops over all ModelClasses and generates a new WTForm class. New form classes are named as [ModelClassName]Form. Sets the new form as an attribute on MarvinForm. Also populates the _param_to_form_lookup dictonary with all ModelClass/WTForm parameters and their corresponding forms. e.g. _param_form_lookup['name'] = marvin.tools.query.forms.IFUDesignForm ''' for key, val in classes.items(): classname = '{0}Form'.format(key) try: newclass = formClassFactory(classname, val, ModelForm) except Exception as e: if self.verbose: warnings.warn('class {0} not Formable'.format(key), MarvinUserWarning) else: self.__setattr__(classname, newclass) self._loadParams(newclass)
Example #6
Source File: schedules.py From incubator-superset with Apache License 2.0 | 5 votes |
def process_form(self, form: Form, is_created: bool) -> None: if form.test_email_recipients.data: test_email_recipients = form.test_email_recipients.data.strip() else: test_email_recipients = None test_slack_channel = ( form.test_slack_channel.data.strip() if form.test_slack_channel.data else None ) self._extra_data["test_email"] = form.test_email.data self._extra_data["test_email_recipients"] = test_email_recipients self._extra_data["test_slack_channel"] = test_slack_channel
Example #7
Source File: app.py From myflaskapp with MIT License | 5 votes |
def login(): if request.method == 'POST': # Get Form Fields username = request.form['username'] password_candidate = request.form['password'] # Create cursor cur = mysql.connection.cursor() # Get user by username result = cur.execute("SELECT * FROM users WHERE username = %s", [username]) if result > 0: # Get stored hash data = cur.fetchone() password = data['password'] # Compare Passwords if sha256_crypt.verify(password_candidate, password): # Passed session['logged_in'] = True session['username'] = username flash('You are now logged in', 'success') return redirect(url_for('dashboard')) else: error = 'Invalid login' return render_template('login.html', error=error) # Close connection cur.close() else: error = 'Username not found' return render_template('login.html', error=error) return render_template('login.html') # Check if user logged in
Example #8
Source File: app.py From myflaskapp with MIT License | 5 votes |
def article(id): # Create cursor cur = mysql.connection.cursor() # Get article result = cur.execute("SELECT * FROM articles WHERE id = %s", [id]) article = cur.fetchone() return render_template('article.html', article=article) # Register Form Class
Example #9
Source File: user_controller.py From codecat with GNU General Public License v3.0 | 5 votes |
def delete_user(request): if check_auth() == False: return redirect("front/auth") class TheForm(Form): id = TextField('id:', validators=[validators.required(), validators.Length(min=1, max=64)]) class Meta: csrf = True csrf_class = tokenform.Ice_CSRF form = TheForm( request.form, meta={'csrf_context': request.remote_addr } ) if request.method == 'POST': token=request.form['csrf_token'] if form.validate(): if form.csrf_token.errors: flash('Error: form token invalid try to post again') else: id=request.form['id'] obj=user_rest_api obj=obj.rest_call("","") obj.token=session['userkey'] handler=obj.Delete_User(id) flash(str(handler)) else: flash('Error: All the form fields are required. ') return render_template('user_forms/user_delete.html', form=form, title="Delete User by ID")
Example #10
Source File: user_controller.py From codecat with GNU General Public License v3.0 | 5 votes |
def insert_user(request): if check_auth() == False: return redirect("front/auth") class TheForm(Form): name = TextField('name:', validators=[validators.required(), validators.Length(min=4, max=35)]) email = TextField('email:', validators=[validators.required(), validators.Length(min=4, max=35)]) password = TextField('password:', validators=[validators.required(), validators.Length(min=4, max=35)]) # owner = TextField('owner:', validators=[validators.required(), validators.Length(min=4, max=12)]) class Meta: csrf = True csrf_class = tokenform.Ice_CSRF form = TheForm( request.form, meta={'csrf_context': request.remote_addr } ) if request.method == 'POST': token=request.form['csrf_token'] if form.validate(): if form.csrf_token.errors: flash('Error: form token invalid try to post again') else: name=request.form['name'] email=request.form['email'] owner=request.form['owner'] password=request.form['password'] obj=user_rest_api obj=obj.rest_call("","") obj.token=session['userkey'] handler=obj.Insert_User(email,name,password,owner) flash(str(handler)) else: flash('Error: All the form fields are required. ') return render_template('user_forms/user_insert.html', form=form, title="Insert User")
Example #11
Source File: user_controller.py From codecat with GNU General Public License v3.0 | 5 votes |
def show_auth(request): if session.get('userkey') == True: if test_token(session['userkey'])==True: img='<img src="/static/codecat1.png" height="400" width="400" >' return render_template('AuthAdmin.html',title="Welcome to Codecat",content=img) class TheForm(Form): email = TextField('email:', validators=[validators.required(), validators.Length(min=4, max=35)]) password = TextField('password:', validators=[validators.required(), validators.Length(min=4, max=35)]) class Meta: csrf = True csrf_class = tokenform.Ice_CSRF form = TheForm( request.form, meta={'csrf_context': request.remote_addr } ) if request.method == 'POST': token=request.form['csrf_token'] if form.validate(): if form.csrf_token.errors: flash('Error: form token invalid try to post again') return render_template('login.html',form=form) if test_auth(request) == True: img='<img src="/static/codecat1.png" height="400" width="400" >' return render_template('AuthAdmin.html',title="Welcome to Codecat",content=img) flash('Error user or password not found !') else: flash('Error: All the form fields are required. ') # token in form.csrf_token return render_template('login.html',form=form)
Example #12
Source File: rule_controller.py From codecat with GNU General Public License v3.0 | 5 votes |
def delete_rule(request): if user_controller.check_auth() == False: return redirect("front/auth") class TheForm(Form): id = TextField('id:', validators=[validators.required(), validators.Length(min=1, max=64)]) class Meta: csrf = True csrf_class = tokenform.Ice_CSRF form = TheForm( request.form, meta={'csrf_context': request.remote_addr } ) if request.method == 'POST': token=request.form['csrf_token'] if form.validate(): if form.csrf_token.errors: flash('Error: form token invalid try to post again') else: id=request.form['id'] obj=rule_rest_api obj=obj.rest_call("","") obj.token=session['userkey'] handler=obj.Delete_rule(id) flash(str(handler)) else: flash('Error: All the form fields are required. ') return render_template('rule_forms/rule_delete.html', form=form, title="Delete rule by ID")
Example #13
Source File: rule_controller.py From codecat with GNU General Public License v3.0 | 5 votes |
def insert_rule(request): if user_controller.check_auth() == False: return redirect("front/auth") class TheForm(Form): title = TextField('title:', validators=[validators.required(), validators.Length(min=3, max=1024)]) class Meta: csrf = True csrf_class = tokenform.Ice_CSRF form = TheForm( request.form, meta={'csrf_context': request.remote_addr } ) if request.method == 'POST': token=request.form['csrf_token'] if form.validate(): if form.csrf_token.errors: flash('Error: form token invalid try to post again') else: try: d={} d['title']=request.form['title'] d['lang']=request.form['lang'] d['description']=request.form['description'] d['level']=request.form['level'] d['match1']=request.form['match1'] d['match2']=request.form['match2'] obj=rule_rest_api obj=obj.rest_call("","") obj.token=session['userkey'] handler=obj.Insert_rule(**d) flash(str(handler)) except Exception as e: flash('Fail: '+ str(e)) else: flash('Error: All the form fields are required. ') return render_template('rule_forms/rule_insert.html', form=form, title="Insert rule")
Example #14
Source File: engine_controller.py From codecat with GNU General Public License v3.0 | 5 votes |
def allsinks(request): if user_controller.check_auth() == False: return redirect("front/auth") class TheForm(Form): path = TextField('path:', validators=[validators.required(), validators.Length(min=1, max=2048)]) lang = TextField('lang:', validators=[validators.required(), validators.Length(min=1, max=32)]) class Meta: csrf = True csrf_class = tokenform.Ice_CSRF form = TheForm( request.form, meta={'csrf_context': request.remote_addr } ) if request.method == 'POST': token=request.form['csrf_token'] if form.validate(): if form.csrf_token.errors: flash('Error: form token invalid try to post again') else: try: d={} d['lang']=request.form['lang'] d['path']=request.form['path'] obj=engine_rest_api obj=obj.rest_call("","") obj.token=session['userkey'] codes_lines=obj.allsinks(**d) flash("Wait five seconds and look the code cache") except Exception as e: flash('Fail: '+ str(e)) else: flash('Error: All the form fields are required. ') return render_template('engine_forms/allsinks.html', form=form, title="Search using all rules")
Example #15
Source File: engine_controller.py From codecat with GNU General Public License v3.0 | 5 votes |
def getsinks(request): if user_controller.check_auth() == False: return redirect("front/auth") class TheForm(Form): sink = TextField('sink:', validators=[validators.required(), validators.Length(min=1, max=1024)]) path = TextField('path:', validators=[validators.required(), validators.Length(min=1, max=2048)]) class Meta: csrf = True csrf_class = tokenform.Ice_CSRF form = TheForm( request.form, meta={'csrf_context': request.remote_addr } ) if request.method == 'POST': token=request.form['csrf_token'] if form.validate(): if form.csrf_token.errors: flash('Error: form token invalid try to post again') else: try: d={} d['lang']=request.form['lang'] d['sink']=request.form['sink'] d['path']=request.form['path'] obj=engine_rest_api obj=obj.rest_call("","") obj.token=session['userkey'] codes_lines=obj.getsinks(**d) flash("Wait five seconds and look the code cache") except Exception as e: flash('Fail: '+ str(e)) else: flash('Error: All the form fields are required. ') return render_template('engine_forms/getsinks.html', form=form, title="Search sink")
Example #16
Source File: base.py From incubator-superset with Apache License 2.0 | 5 votes |
def validate_json(form: Form, field: Field) -> None: # pylint: disable=unused-argument try: json.loads(field.data) except Exception as ex: logger.exception(ex) raise Exception(_("json isn't valid"))
Example #17
Source File: orm.py From jbox with MIT License | 5 votes |
def model_form(model, base_class=Form, only=None, exclude=None, field_args=None, converter=None): """ Create a wtforms Form for a given Django model class:: from wtforms.ext.django.orm import model_form from myproject.myapp.models import User UserForm = model_form(User) :param model: A Django ORM model class :param base_class: Base form class to extend from. Must be a ``wtforms.Form`` subclass. :param only: An optional iterable with the property names that should be included in the form. Only these properties will have fields. :param exclude: An optional iterable with the property names that should be excluded from the form. All other properties will have fields. :param field_args: An optional dictionary of field names mapping to keyword arguments used to construct each field object. :param converter: A converter to generate the fields based on the model properties. If not set, ``ModelConverter`` is used. """ field_dict = model_fields(model, only, exclude, field_args, converter) return type(model._meta.object_name + 'Form', (base_class, ), field_dict)
Example #18
Source File: forms.py From marvin with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __repr__(self): nforms = len([f for f in self.__dict__.keys() if 'Form' in f]) return ('<MarvinForm (release={0._release}, n_parameters={1}, n_functions={2}, ' 'n_forms={3})>'.format(self, len(self._param_form_lookup), len(self._param_fxn_lookup), nforms))
Example #19
Source File: forms.py From marvin with BSD 3-Clause "New" or "Revised" License | 5 votes |
def formClassFactory(name, model, baseclass): ''' Generates a new WTForm Class based on SQLalchemy Model Class. Subclasses a base WTF Form class that also contains the SQLAlchemy Model Class information inside it. Each class contains as attributes: Meta = a class called Meta. Meta.model contains the SQLalchemy ModelClass data = a dictionary of parameters: form input that gets mapped to the sqlalchemy parameter errors = a dictionary of errors returned by invalid form validation validate = a method to validate all elements in this form parameter_X = a WTForm Field mapped to respective sqlalchemy table column e.g. The ModelClass IFUDesign mapped to mangadatadb.ifu_design sql table gets transformed into WTForm IFUDesignForm, with IFUDesignForm.Meta.model = marvin.db.models.DataModelClasses.IFUDesign Parameters: name (str): The name of the Form Class mdoel (class): The SQLAlchemy Model Class baseclass (class): The base class to sub class from Returns: the new WTF form subclass ''' Meta = type('Meta', (object,), {'model': model}) newclass = type(name, (baseclass,), {'Meta': Meta}) return newclass # build a wtform select field for operators; tested but no longer used # can't seem to attach operator field to every individual parameter
Example #20
Source File: db.py From googleapps-message-recall with Apache License 2.0 | 5 votes |
def model_form(model, base_class=Form, only=None, exclude=None, field_args=None, converter=None): """ Creates and returns a dynamic ``wtforms.Form`` class for a given ``db.Model`` class. The form class can be used as it is or serve as a base for extended form classes, which can then mix non-model related fields, subforms with other model forms, among other possibilities. :param model: The ``db.Model`` class to generate a form for. :param base_class: Base form class to extend from. Must be a ``wtforms.Form`` subclass. :param only: An optional iterable with the property names that should be included in the form. Only these properties will have fields. :param exclude: An optional iterable with the property names that should be excluded from the form. All other properties will have fields. :param field_args: An optional dictionary of field names mapping to keyword arguments used to construct each field object. :param converter: A converter to generate the fields based on the model properties. If not set, ``ModelConverter`` is used. """ # Extract the fields from the model. field_dict = model_fields(model, only, exclude, field_args, converter) # Return a dynamically created form class, extending from base_class and # including the created fields as properties. return type(model.kind() + 'Form', (base_class,), field_dict)
Example #21
Source File: ndb.py From googleapps-message-recall with Apache License 2.0 | 5 votes |
def model_form(model, base_class=Form, only=None, exclude=None, field_args=None, converter=None): """ Creates and returns a dynamic ``wtforms.Form`` class for a given ``ndb.Model`` class. The form class can be used as it is or serve as a base for extended form classes, which can then mix non-model related fields, subforms with other model forms, among other possibilities. :param model: The ``ndb.Model`` class to generate a form for. :param base_class: Base form class to extend from. Must be a ``wtforms.Form`` subclass. :param only: An optional iterable with the property names that should be included in the form. Only these properties will have fields. :param exclude: An optional iterable with the property names that should be excluded from the form. All other properties will have fields. :param field_args: An optional dictionary of field names mapping to keyword arguments used to construct each field object. :param converter: A converter to generate the fields based on the model properties. If not set, ``ModelConverter`` is used. """ # Extract the fields from the model. field_dict = model_fields(model, only, exclude, field_args, converter) # Return a dynamically created form class, extending from base_class and # including the created fields as properties. return type(model._get_kind() + 'Form', (base_class,), field_dict)
Example #22
Source File: orm.py From googleapps-message-recall with Apache License 2.0 | 5 votes |
def model_form(model, base_class=Form, only=None, exclude=None, field_args=None, converter=None): """ Create a wtforms Form for a given Django model class:: from wtforms.ext.django.orm import model_form from myproject.myapp.models import User UserForm = model_form(User) :param model: A Django ORM model class :param base_class: Base form class to extend from. Must be a ``wtforms.Form`` subclass. :param only: An optional iterable with the property names that should be included in the form. Only these properties will have fields. :param exclude: An optional iterable with the property names that should be excluded from the form. All other properties will have fields. :param field_args: An optional dictionary of field names mapping to keyword arguments used to construct each field object. :param converter: A converter to generate the fields based on the model properties. If not set, ``ModelConverter`` is used. """ field_dict = model_fields(model, only, exclude, field_args, converter) return type(model._meta.object_name + 'Form', (base_class, ), field_dict)
Example #23
Source File: fields.py From udata with GNU Affero General Public License v3.0 | 5 votes |
def field_parse(cls, value, *args, **kwargs): kwargs['_form'] = WTForm() kwargs['_name'] = 'extra' field = cls(*args, **kwargs) field.process_formdata([value]) return field.data
Example #24
Source File: form.py From RSSNewsGAE with Apache License 2.0 | 5 votes |
def __init__(self, *args, **kwargs): warnings.warn(FlaskWTFDeprecationWarning( '"flask_wtf.Form" has been renamed to "FlaskForm" ' 'and will be removed in 1.0.' ), stacklevel=3) super(Form, self).__init__(*args, **kwargs)
Example #25
Source File: db.py From RSSNewsGAE with Apache License 2.0 | 5 votes |
def model_form(model, base_class=Form, only=None, exclude=None, field_args=None, converter=None): """ Creates and returns a dynamic ``wtforms.Form`` class for a given ``db.Model`` class. The form class can be used as it is or serve as a base for extended form classes, which can then mix non-model related fields, subforms with other model forms, among other possibilities. :param model: The ``db.Model`` class to generate a form for. :param base_class: Base form class to extend from. Must be a ``wtforms.Form`` subclass. :param only: An optional iterable with the property names that should be included in the form. Only these properties will have fields. :param exclude: An optional iterable with the property names that should be excluded from the form. All other properties will have fields. :param field_args: An optional dictionary of field names mapping to keyword arguments used to construct each field object. :param converter: A converter to generate the fields based on the model properties. If not set, ``ModelConverter`` is used. """ # Extract the fields from the model. field_dict = model_fields(model, only, exclude, field_args, converter) # Return a dynamically created form class, extending from base_class and # including the created fields as properties. return type(model.kind() + 'Form', (base_class,), field_dict)
Example #26
Source File: ndb.py From RSSNewsGAE with Apache License 2.0 | 5 votes |
def model_form(model, base_class=Form, only=None, exclude=None, field_args=None, converter=None): """ Creates and returns a dynamic ``wtforms.Form`` class for a given ``ndb.Model`` class. The form class can be used as it is or serve as a base for extended form classes, which can then mix non-model related fields, subforms with other model forms, among other possibilities. :param model: The ``ndb.Model`` class to generate a form for. :param base_class: Base form class to extend from. Must be a ``wtforms.Form`` subclass. :param only: An optional iterable with the property names that should be included in the form. Only these properties will have fields. :param exclude: An optional iterable with the property names that should be excluded from the form. All other properties will have fields. :param field_args: An optional dictionary of field names mapping to keyword arguments used to construct each field object. :param converter: A converter to generate the fields based on the model properties. If not set, ``ModelConverter`` is used. """ # Extract the fields from the model. field_dict = model_fields(model, only, exclude, field_args, converter) # Return a dynamically created form class, extending from base_class and # including the created fields as properties. return type(model._get_kind() + 'Form', (base_class,), field_dict)
Example #27
Source File: orm.py From RSSNewsGAE with Apache License 2.0 | 5 votes |
def model_form(model, base_class=Form, only=None, exclude=None, field_args=None, converter=None): """ Create a wtforms Form for a given Django model class:: from wtforms.ext.django.orm import model_form from myproject.myapp.models import User UserForm = model_form(User) :param model: A Django ORM model class :param base_class: Base form class to extend from. Must be a ``wtforms.Form`` subclass. :param only: An optional iterable with the property names that should be included in the form. Only these properties will have fields. :param exclude: An optional iterable with the property names that should be excluded from the form. All other properties will have fields. :param field_args: An optional dictionary of field names mapping to keyword arguments used to construct each field object. :param converter: A converter to generate the fields based on the model properties. If not set, ``ModelConverter`` is used. """ field_dict = model_fields(model, only, exclude, field_args, converter) return type(model._meta.object_name + 'Form', (base_class, ), field_dict)
Example #28
Source File: db.py From jbox with MIT License | 5 votes |
def model_form(model, base_class=Form, only=None, exclude=None, field_args=None, converter=None): """ Creates and returns a dynamic ``wtforms.Form`` class for a given ``db.Model`` class. The form class can be used as it is or serve as a base for extended form classes, which can then mix non-model related fields, subforms with other model forms, among other possibilities. :param model: The ``db.Model`` class to generate a form for. :param base_class: Base form class to extend from. Must be a ``wtforms.Form`` subclass. :param only: An optional iterable with the property names that should be included in the form. Only these properties will have fields. :param exclude: An optional iterable with the property names that should be excluded from the form. All other properties will have fields. :param field_args: An optional dictionary of field names mapping to keyword arguments used to construct each field object. :param converter: A converter to generate the fields based on the model properties. If not set, ``ModelConverter`` is used. """ # Extract the fields from the model. field_dict = model_fields(model, only, exclude, field_args, converter) # Return a dynamically created form class, extending from base_class and # including the created fields as properties. return type(model.kind() + 'Form', (base_class,), field_dict)
Example #29
Source File: ndb.py From jbox with MIT License | 5 votes |
def model_form(model, base_class=Form, only=None, exclude=None, field_args=None, converter=None): """ Creates and returns a dynamic ``wtforms.Form`` class for a given ``ndb.Model`` class. The form class can be used as it is or serve as a base for extended form classes, which can then mix non-model related fields, subforms with other model forms, among other possibilities. :param model: The ``ndb.Model`` class to generate a form for. :param base_class: Base form class to extend from. Must be a ``wtforms.Form`` subclass. :param only: An optional iterable with the property names that should be included in the form. Only these properties will have fields. :param exclude: An optional iterable with the property names that should be excluded from the form. All other properties will have fields. :param field_args: An optional dictionary of field names mapping to keyword arguments used to construct each field object. :param converter: A converter to generate the fields based on the model properties. If not set, ``ModelConverter`` is used. """ # Extract the fields from the model. field_dict = model_fields(model, only, exclude, field_args, converter) # Return a dynamically created form class, extending from base_class and # including the created fields as properties. return type(model._get_kind() + 'Form', (base_class,), field_dict)
Example #30
Source File: user_controller.py From codecat with GNU General Public License v3.0 | 4 votes |
def update_user(user_id): if check_auth() == False: return redirect("front/auth") class TheForm(Form): name = TextField('name:', validators=[validators.required(), validators.Length(min=4, max=35)]) email = TextField('email:', validators=[validators.required(), validators.Length(min=4, max=35)]) password = TextField('password:', validators=[validators.required(), validators.Length(min=4, max=35)]) # owner = TextField('owner:', validators=[validators.required(), validators.Length(min=4, max=12)]) class Meta: csrf = True csrf_class = tokenform.Ice_CSRF form = TheForm( request.form, meta={'csrf_context': request.remote_addr } ) if request.method == 'POST': #"csrf_token" in request.form: if len(str(user_id)) >=1 and len(request.form['csrf_token']) > 1 : token=request.form['csrf_token'] if form.validate(): if form.csrf_token.errors: flash('Error: form token invalid try to post again') else: name=request.form['name'] email=request.form['email'] owner=request.form['owner'] password=request.form['password'] obj=user_rest_api obj=obj.rest_call("","") obj.token=session['userkey'] handler=obj.Update_User(str(user_id),email,name,password,owner) flash(str(handler)) else: flash('Error: All the form fields are required. ') obj=user_rest_api obj=obj.rest_call("","") obj.token=session['userkey'] obj.Return_User_by_ID(str(user_id)) users={} rows=[] rows= obj.json_output users={"id": str(rows[0]),"name": str(rows[1]),"email": str(rows[2]),"owner": str(rows[3]),"date": str(rows[4]) } return render_template('user_forms/user_update.html', form=form, users=users, title="Update data of user")