Search code examples
pythonflaskflask-flatpages

Flask Flatpages list of folders. BuildError


I'm using Flask with Flask-FlatPages and I'm trying to get a list of all the subdirectories in the Flatpages /pages folder. These folders should appear as a link that when clicked append the foldername on the url. In the pages folder are two subdirectories: misc and test. I have tried this:

@app.route('/list')
def listdir():
    folders = os.listdir('./pages')
    return render_template('list.html', folders=folders)

and the template is using this part:

<ul class="unstyled">
{% for folder in folders %}
    <li>
    <a href="{{ url_for("folder", name=folder) }}"><h3>{{ folder }}</h3></a>
    </li>
 ....

but it just gives me an empty page.

i have tried a bit and now it gives me at least an error:

BuildError: ('folder', {'name': 'test'}, None)

Solution

  • With this BuildError, Flask is telling you that it can not find the URL for a view named "folder" that takes a single "name" parameter. Do you have such a view? Please provide all of your views’ code.