Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't execute Python from the rendered template, but you can do what you want by combining Python with Javascript. I'm going to use Flask as an example web framework but it should be pretty clear what it does even if you're not familiar with Flask in particular.</p> <p>The idea is that you have two routes/addresses. One serves you the basic view where you want your "Updating..." thing to take place. The other route returns an HTML fragment that consists of the directory data rendered to a suitable HTML presentation. So something like this:</p> <p>Python:</p> <pre><code>def _walk_through_directories(): """ Walk through directories and gather the data you want and return it in some collection for example. """ ... return directory_data @app.route('/directories') def directories(): return render_template('directories.html') @app.route('/directories/fragment') def directories(): directory_data = _walk_through_directories() return render_template('directories_fragment.html', directory_data=directory_data) </code></pre> <p>Now when the user enters your basic page at /directories, he/she sees your basic template that does not yet contain anything about the directory data. To remedy this, you can execute Javascript after the document is done loading and fetch the content by doing a HTTP GET with Ajax. So something like this:</p> <p>Javascript + jQuery called from "directories.html":</p> <pre><code>$('#message-box').html('Updating...'); $.get('/directories/fragment', function(data) { $('#result-box').html(data); $('#message-box').html('All done!'); }); </code></pre> <p>So the idea is to serve the basic page with Python and then use client-side Javascript to fetch the "dynamic" content. Please note that I just threw this together, so it might be missing a parenthesis or two somewhere and you should add proper error handling and all that jazz.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload