I’m relatively new to Flask and I have a sort of philosophical/design question for those who are more experienced/knowledgeable…
I have a Flask app that stores an inventory of boxes in a mySQL DB. I want to be able to switch the views between a desktop appropriate-view (think a table of rows with item name, item photo, date added, box number/name, location, etc) to a mobile-friendly view that is just a grid of photos that you touch to go to a separate detail page. Eventually I’ll save the last view “type” in a cookie and default to that view unless the user switches views. I mention this because I think it could have system design implications.
My current method for having the two views is to have two separate routes, one for each view. For example, I have a /search_results
route that calls the desktop-appropriate template and a /photo_search_results
route that returns the grid of photos. There are about five of these views: search, show all items, items in a specific box, etc.
However, there are obviously other ways to do this. I could implement the views as two separate templates that are returned by the same route with an if/then based on the user’s saved view preference… or I could put the switching logic into the template itself.
This is more a philosophical question than a specific coding question. My current method works, but it could have performance, maintenance, or other implications.