Skip to Content
Flask Framework Cookbook - Second Edition
book

Flask Framework Cookbook - Second Edition

by Shalabh Aggarwal
July 2019
Beginner to intermediate
302 pages
9h 38m
English
Packt Publishing
Content preview from Flask Framework Cookbook - Second Edition

How to do it...

Follow these steps in order to implement the lazy evaluation of translations:

  1. To mark all the field labels in the product and category forms as translatable, make the following changes to my_app/catalog/models.py:
from flask_babel import _ 
 
class NameForm(FlaskForm): 
    name = StringField(_('Name'), validators=[InputRequired()]) 
 
class ProductForm(NameForm): 
    price = DecimalField(_('Price'), validators=[ 
        InputRequired(), NumberRange(min=Decimal('0.0')) 
    ]) 
    category = CategoryField( 
        _('Category'), validators=[InputRequired()], coerce=int 
    ) 
    image = FileField(_('Product Image')) 
 
class CategoryForm(NameForm): 
    name = StringField(_('Name'), validators=[ 
        InputRequired(), check_duplicate_category() 
    ]) 

Notice that all the field labels ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Writing a Web Application with Flask

Writing a Web Application with Flask

Doug Farrell
Mastering Flask

Mastering Flask

Jack Stouffer

Publisher Resources

ISBN: 9781789951295Supplemental Content