Create directory of dynamically created html files. Flask
<p>I've got a simple flask app, with a templates folder with a bunch of html files that are created by a separate program. I want to (1) serve each of these html files by hitting <code>localhost:8888/&lt;html_filename&gt;</code> and
(2) create a directory with hyperlinks to these endpoints on my main <code>/</code> endpoint. </p>

<p>Thoughts on how I could get a jinja template to create links to those endpoints? Heres what I've been thinking.</p>

<p>Flask App:</p>

<pre><code>@app.route('/')
def index():
    reports = [f_name for f_name in os.listdir("templates") if f_name.endswith(".html")]
    return render_template("index.html", reports=reports)

@app.route('/&lt;report&gt;')
def render_report(report):
    return render_template(report+'.html')
</code></pre>

<p>index.html:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
    &lt;head&gt;
        &lt;title&gt;Report Directory&lt;/title&gt;
    &lt;/head&gt; 
    &lt;body&gt;
        &lt;ul&gt;
        {% for r in reports %}
            &lt;li&gt;
                &lt;a href="{{ r }}"&gt;{{ r }}&lt;/a&gt;
            &lt;/li&gt;
        {% endfor %}
        &lt;/ul&gt;
    &lt;/body&gt;
&lt;/html&gt; 
</code></pre>

<p>Off the top of my head and not tested in any way define a route along the lines of the following:</p>

<pre><code>@route("/&lt;string:slug&gt;/", methods=['GET'])
def page(self, slug):

    if slug_exists_as_a_html_file(slug):

        return render_template(slug)

    abort(404)
</code></pre>

<p>The function (or inline it) )<code>slug_exists_as_a_html_file</code> needs to return True if the slug matches a valid html template file, otherwise false.</p>

<p>To generate your report listing use something like :</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
    &lt;head&gt;
        &lt;title&gt;Report Directory&lt;/title&gt;
    &lt;/head&gt; 
    &lt;body&gt;
        &lt;ul&gt;
        {% for r in reports %}
            &lt;li&gt;
                &lt;a href="{{ url_for('page', slug=r) }}"&gt;{{ r }}&lt;/a&gt;
            &lt;/li&gt;
        {% endfor %}
        &lt;/ul&gt;
    &lt;/body&gt;
&lt;/html&gt; 
</code></pre>

python flask