Example of "best practice" Flask Single-Page App (with a restful api?)

Hi all.

I want to improve my web app by cleaning up the Flask design. I’m new to Flask but I think I want to combine a) a single-page app (only python with jinja2) with a restful api that sends data and prediction back and forth…

However, if I search I always end up with backend (python, flask) and frontend (cue/ angular, js) stuff. If possible I’d avoid programming in JS…

Is this not done at all? Am I missing something… Or is a RESTful API overkill here anyways? I want to do it mainly as a learning experience and since I have this nagging feeling this is not done right atm. :wink:

I also think I need to make the setup more stable. Currently the model is in the global scope. First experiments with hooks and GradCAM generation (not in the app yet, work in a notebook) give me a Segfault if run through my current setup.

Not sure if I’m making sense?

The current version of the app is here:

Any pointers and tips are most welcome…

1 Like

What you’re proposing is possible, but like you said it’s an overkill. Most web-apps consume Restful apis from the frontend thus the reason for JS.

Though you can consume API using python and then render to the frontend though that won’t be an SPA in the sense of it. You can read more about SPA here.