[Flask] A best practices question
William Mayor
mail at williammayor.co.uk
Fri Jun 8 05:03:40 EDT 2018
In my experience you can avoid writing lots of boilerplate code using
libraries like WTForms, Marshmallow, SQLAlchemy, Flask-RESTful, etc. etc.
This mostly leaves you with writing just those bits of code that matter
to you. What type of ID is this field? How should it validate? etc. etc.
When it comes to gluing the libraries together I just plump for really
simple, mostly identical routes. Anytime I've tried to refactor these
routes into reusable classes or helper functions I've found that there
are always too many exceptions to the rule that force me to deviate.
When there are times that I'm writing substantial bits of route code
that are all identical, I refactor them into a decorator that I use on
the routes that need them. This doesn't happen often, as most of the
time the substantial yet identical code is taken care of by the
libraries I'm using.
Hope that helps :)
<https://www.postbox-inc.com>
> Les Dunaway <mailto:les at dunawaygroupllc.com>
> 8 June 2018 at 01:05
> Yes, it is like that - however, the question wasn't like that
> I can implement a route to catch a click from a selection; I can write
> code to put up the next screen; ...
>
> My question is is there an accepted way to avoid writing, essentially,
> the same code for each choice (seems like there must be ;-)
>
> Les Dunaway
> 770-490-7546
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
> Jerry Mccreary <mailto:jerry.mccreary at mac.com>
> 7 June 2018 at 18:10
> Are you describing a scenario like Flask-Admin handles?
> i.e. Master list view, Detail view with create/update/delete?
>
> Depending on your needs, implementing a REST api may be useful, in
> that it doesn’t require a full page-reload to create/update/delete
> records.
>
> --
> Jerry
>
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
> Les Dunaway <mailto:les at dunawaygroupllc.com>
> 7 June 2018 at 16:29
> Folks,
>
> There's a common sequence of events - put up a screen with selection
> options; put up a screen with detail input options; process; return
> results
>
> ie: A screen that says "You can make a new widget, update an existing
> widget or delete a widget"
> The user selects make a new widget and the next screen is the
> input form for a new widget
> ...
>
> My question is, after a lot of searching and reading, is there a know
> / accepted best practice for structuring this sequence
>
> ------------------------------------------------------------------------
> Les Dunaway
> 770-490-7546
>
>
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20180608/a90e762e/attachment-0001.html>
More information about the Flask
mailing list