Publishing with nested folder structure for Python Flask - information

Issues related to previewing and publishing your web site.
Post Reply
drcjb
 
 
Posts: 4
Joined: Thu Feb 09, 2023 7:19 pm

Publishing with nested folder structure for Python Flask - information

Post by drcjb »

Hello Everyone,

I was going to submit a problem request but I managed to solve the issue myself but wanted to share my findings. I am using WWB18 to generate a simple web site for my mobile phone to control some automation features of a model I have built. The automation programs are written in Python 3 so it was logical that I used the Python 3 Flask app as the server. Flask has very specific requirements in terms of folder structure which are as follows:

App folder
----\templates
----\static
--------\css
--------\images
--------\js

Site Manager was easily set up to refect this structure. The .html files including index.html go in the templates folder and the .css files are in \static\css etc. In WWB Tools->Options->Publish I changed all the file type paths appropiately (e.g. ..\static\images for jpg files etc.) html files was set to templates. It seems that WWB presumes that all the static folders are under the folder containing the index.html file hence my use of the ..\ in the folder path to reach the static folder. This all worked providing I used \ to separate foldersif I used / only the index.html file was published! (Normal because Windows requires folder seperators as \ not /).

So the publishing in the Flask structure worked but as the same file paths from Tools->Options->Publish are used by WWB to indicate the paths in the href statements in index.html the link statements looked odd i.e. <link href="..\static\css/index.css" rel="stylesheet"> as the path seperaters are both / and \! To my great suprise (and pleasure) my Firefox browser does not mind this mixture and renders the pages correctly!

In any case the link statements have to be modified for Flask to use the {{url_for.....}} command and I do this by using the python app that launches the Flask server to modify index.html before the server starts but at least now I can test the build in WWB and then publish in the correct structure for Flask.

My thanks to Pablo and the team for WWB18 - a truely amazing product!

Best regards, Colin
Using WWB18 to make a site for the automation of a model using Python 3 and Flask (the Python server).
Post Reply