Forums

html refreshing not showing up

I created a small web app using Flask. Based on inputs from users the app dynamically creates a html and then prints it to book.html in my templates folder, which should be properly rendered in /book. Despite the fact that if check the file directly the data is correct, in the browser the data is either not showing or showing and then disappearing.

I don't know whether it's relevant but the book.html is actually created by a separate script which I'm running as an always-on task and it includes a meta tag to refresh the page.

Actually solved it by rendering the page with flask variables rather than a html generated elsewhere

Thanks for posting that! I was just about to suggest doing exactly that. Flask needs to be reloaded if templates change (sometimes but not always) so generating a template from code can lead to a site that's periodically unresponsive because it's being restarted. Using Flask template variables like you've done now is the best solution.

This raises a question for me. I am trying to rehost a python app from my PC that creates an HTML file and then displays that for the user who posted the initial request. Is there a way for PythonAnywhere to bring the generated HTML up in the current browser? I would really not want to re-write the back-end code using Flask template variables. I want the python code to be the same for my PC as for your site, apart from the front-end logic. I uploaded a sample HTML file and when I clicked on it in your file browser it brought is up in the editor.

If you put the HTML file in a directory that is served using our static files system then it will be accessible via your PythonAnywhere website. That said, I really would suggest looking into using something like Flask -- it will scale much better.