Forums

Updating my html template files using my pythonanywhere python code?

I have developed a python script that creates html maps using folium.

In addition, I have used Flask to create a number of webpages that show these html source files

I also have a page which can prompt a user to load a source file which if submitted, will update the html maps files.

When doing this locally, I can save to my local template drive however when all is loaded on pythonanwhere, I note, the source template files fail to refresh.

I have read some tutorials, and they suggest my best option is to load all files into a GIT repo and push/pull/hook between GIT and python anywhere. (I still need to do more reading on this)

If it is agreed, that this is the option for storing files, can I ask, is there away for me to update my templates in GIT after a user loads a new file and triggers my code to run??

Today, the file will run however the maps do not update in python anywhere.

Feedback appreciated.

That worked on your local machine because it was probably in development mode. That means that it would be more eager about reloading templates. If you are not using the templating features in those pages, just serve them as static files: https://help.pythonanywhere.com/pages/StaticFiles/

I'm not entirely sure that I understand what you're trying to accomplish with git.

Thanks for the response Glenn,

My webpages point to the template folder where I save my maps also.

These maps have been created using python/folium and saved to the template folder.

In addition, these updated via the python script every time a user loads a new file to the webpage. (this should trigger the python code to run and create the new maps and save these in html format in the template folder.

My problem is that the html maps don't seem to be updating in python anywhere and I am not 100% on how to do this correctly.

All help appreciated. Thanks

Are the files actually being changed when an update has completed?

If I run the python script locally, the files will change yes, the timestamps etc update and map data will align to the new file content that has been loaded.

When I run my python script on the pythonanywhere server and load the file, the html files in my sites template folder then fail to update.

My python script states something like the below

map.save("templates"+"\"+"map.html")

Would it be the case that I need to update this to align to the python anywhere web server maybe?

If they are not changed on the disk, then you will need to work out what is going wrong to prevent them from being updated. In particular, make sure that, you do not use relative paths without paying attention to your working directory: https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/