Calling Python Functions In Html File In Flask
I have a list of folders in my python file, and in an HTML file I iterate over the list to display the names of each folder on my page. {% for folder in folders %} <
Solution 1:
With the assumption that folder
is something whose contents you'd want to return dynamically as its own page, the appropriate way to do this would be to have a separate route and view that handles folders. Something like the following:
@app.route("/folder/<folder_name>/")deffolder(folder_name):
# do something with folder_namepass
And in your HTML you would link to it as follows:
<ahref="{% url_for('folder', folder_name=folder) %}">{{ folder }}</a>
Obviously you'd want to update the route accordingly, depending on the contents of folder
, but that's the "Flask way" of linking to dynamic content.
Post a Comment for "Calling Python Functions In Html File In Flask"