Tools: Visual Studio
Technology : Python, Flask
Assumptions: You already know the basics of flask, html and python.
Steps:
- First of all install flask-wtf, a library for creating forms.
- Type command "pip install flask-wtf" in the terminal and press enter.
- First of all create a secret key in your app.py file. This key is very necessary to operate the forms. You can assign any value to the key of your choice though.
- app.config['SECRET_KEY'] = 'dnbna'
- Once that is done, create a new html file, "forms.py" and import the required modules:
- Now create a class and initialize the variables, your forms.py will look something like this below:
- In the step above, we have created three variables for a Signup form and initialized them.
- Now to display these forms we need to have an html file. So create form.html and access the fields created above:
- Now go to your main app.py file, where you create the routes for the application and import the signup form class by:
- from forms import SignupForm
- Once you have done this create a signup route, access the form object and pass it to the form.html page.
RESULT:
This is all, now run the flask application and enter "localhost:5000/signup" in the browser. You will see a form like this below:
Right now the form does nothing, it was just to show you how to create a very simple form using flask-wtf library.
Right now the form does nothing, it was just to show you how to create a very simple form using flask-wtf library.
Thanks to https://www.youtube.com/@TheCodex for helping me to learn these concepts.

Comments
Post a Comment