rmed.blog

Posts tagged 'flask'

Dynamic fields with Flask-WTF

02 Mar 2019

Lately I've been working on a side project that requires dynamically adding or removing fields to a form: ideally, I should be able to add any number of fields and the server should receive the data correctly.

While a combination of FieldList and FormField works great when adding fields in the backend, I wanted to dynamically add and remove fields in the client (through Javascript) without having to send requests to the server until finally submitting the form with all the dynamic fields. Here's how that went.

TL;DR: Example code is available at https://gist.github.com/rmed/def5069419134e9da0713797ccc2cb29.

Tags: flask fields javascript wtforms dynamic

WaffleConf and multiprocess

25 Aug 2015

Version 0.2.0 of Flask-WaffleConf has just been released and includes support for multiprocess deployments. Here I will explain the problems encountered and the "solution" reached.

Tags: flask database waffleconf extension python multiprocess

Flask-WaffleConf

19 Aug 2015

Flask-WaffleConf is a Flask extension that allows you to store configuration variables in the database, read them on startup and update them on runtime. It's kind of an experiment in order to try making a Flask extension from scratch and add the functionality to the website in a modular way. If you are wondering about the reason behind the name, go ask @adolphenom @captainepoch.

The way it works is pretty simple:

  • You define a database model that will act as configuration store
  • Instantiate the WaffleConf object with the application
  • Register the view with any Blueprint

For the time being (you know... alpha state), I've just added a peewee configuration store, but creating stores for other databases should not be too complicated: simply subclass the WaffleStore class and you are ready to go. However, I would recommend checking the documentation first, just in case :)

Released under GPLv2+ license.

Comments, issues and pull requests are more than welcome!

Tags: flask python waffleconf extension database