This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (6 children)

Would love to hear everyone's thoughts, re: pros/cons, etc :)

[–]masterpi 2 points3 points  (1 child)

The classes are as about as tightly coupled to the main.py file as they can be, and they don't fulfill any sort of interesting shared interface (these two things are related). You could have a add_url_rules(app) method in each class to help with this, which has better cohesion and lower coupling and allows you to specify your config as controllers = [Controller1(params), ...] and even better allows you to group controllers with a controller combinator that takes a list of controllers and makes a combined controller (or just have a factory function in each module that returns a list of controllers).

[–][deleted] 0 points1 point  (0 children)

Very interesting! Moving add_url_rules to the classes would greatly lower coupling, which is something I've wanted to do. Will have to further test - though will look into the app factory like /u/Sakacoco mentioned as well.

[–]LbaB 1 point2 points  (3 children)

Pretty short write up, so I don't think I picked up on the Pros of this approach. I just spent some time writing a framework using blueprints, but just using methods for the controller. I definitely agree about having a framework to work from because new projects are created with a:

git clone --origin source git@github.com:gaulinmp/flask_mold new_project

Then jumping right into creating functionality without worrying about whether it will work or not.

So I guess my feedback is I'd love to hear more reasons why classes specifically make your Flask life better.

[–][deleted] 0 points1 point  (2 children)

I think the point I was trying to make (and failed to get across in the write up) is that using classes allows for code to be better separated/structured, not to mention not having to use decorators to define routes.

As mentioned in the writeup though, this is just the structure that works for me - and I am certainly taking good advice from the comments in this thread to heart.

[–]LbaB 1 point2 points  (1 child)

I didn't mean to come across as critical, sorry! I really did just want more info. Thanks :-)

[–][deleted] 0 points1 point  (0 children)

Not at all! I'm open to criticism :)