Forums

Running Python After Response/Refresh?

I'm a relatively new programmer (and very new to web hosting). There's an app I've written that generates new content every time it's run; specifically, it's a deck generator for Magic: the Gathering. What matters in my case is that I want the user to be able to get a new deck either by refreshing the page or at the click of a button.

I went through the 1st Flask tutorial and made my page using Flask, but found (which I guess I should have expected) that the program only runs once and then shows the same content always unless I refresh the server. A little googling suggests to me that Flask is not well-suited to the task I want.

What aside from Flask should I try to use? Is what I want possible in Django, web2py, or Bottle?

Any guidance much appreciated.

Limited knowledge in this, but I think you could use javascript/ajax to make calls to your server to gain a new deck on button press. Maybe creating an api that you call (ajax request) and that returns a new deck, then javascript can update the page. This javascript/ajax would be written in your template from flask

the flask page is served once, then its the job of the web page on the browser to refresh according to buttons pressed or other events such as time, forms filled in etc

Start simple. Good luck on the learning curve!

Javascript solution suggested by @jamesdavies000 sound like the way to go.