jeudi 18 juin 2020

How do I set a form value by code in flask?

I am using Flask and tailwind CSS form for creating product categories. Now I want, when a user clicks on the edit button (screenshot added) old data should set on the form which I am using to create a category for preview. How to do this? Since I am using Tailwind CSS so FlaskForm is not a suitable option.

Image For Refrence

HTML Code:

<a href="" class="text-blue-400 hover:text-blue-600 underline">Edit</a>

Flask Code:

@app.route('/editcat', methods=['GET', 'POST'])
@login_required
def editcat():
   cat_id=request.args.get('cat_id')
   fetched_category=Category.query.get(cat_id)
   print(fetched_category)
   if request.method =='POST':
      fetched_category.category_name = request.form['category_name']
      db.session.commit()
   form.category_name.data = fetched_category.category_name
   return render_template('dashboard.html', form=form)

form.category_name.data = fetched_category.category_name Its not working because I am using tailwind. Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire