
Learning Flask Framework

We have covered how to save and modify tags on our entries. One of the most common approaches to managing tags is to use a comma-separated text input, so we might list the tags as Python, Flask, Web-development. With WTForms this seems pretty straightforward, since we would just use a StringField
. The fact that we are dealing with a database relationship, though, means that at some point we need to do some processing to convert between Tag
models and a comma-separated string.
While there are many ways we could accomplish this, we will implement a custom field class TagField
, which will encapsulate all the logic for translating between comma-separated tag names and Tag
model instances.
Another option would be to create a property on the Entry
model. A property looks like a normal object attribute, but it is actually a combination of getter and (sometimes) setter methods. Since WTForms can automatically work with our model attributes, this means that, if...
Change the font size
Change margin width
Change background colour