O'Reilly logo

Instant Flask Web Development by Ron DuPlain

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling forms and file uploads (Simple)

Let's get data from the user. Before we begin, remember to NEVER trust user input because sooner or later someone (or someone's script) with malicious intent will try to break your application.

Getting ready

We are working from the forms.py file inside the sched directory of our project.

How to do it...

  1. Now that we have a data model, we need to present a form to the user in order to fill our database and validate user input to make sure it matches our schema. You can validate incoming data using any tools you like. We will use WTForms in our scheduler.
  2. Update requirements.txt:
    Flask
    Flask-Script
    Flask-SQLAlchemy
    WTForms
  3. Then:
    $ pip install -r requirements.txt
    
  4. WTForms models forms with classes in a similar style ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required