added load_subs function #20

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants

anschwa commented Jan 4, 2014

This enables you to load the files from other sub-directories in the FlatPages Root by specifying a relative path into load_subs. It seems to behave like the pages variable often set like this pages = FlatPages(Flask(__name__)).

added load_subs function
This enables you to load the files from other sub-directories in the FlatPages Root by specifying a relative path into `load_subs`. It behaves like the `pages` variable often set like this `pages = FlatPages(Flask(__name__))`.
Collaborator

playpauseandstop commented Feb 2, 2014

Hi!

Can you add tests or example why we need load_subs method?

anschwa commented Feb 2, 2014

Yes. Here is how you could load all the files in the flatpages directory:

@app.route('/')
def home():
    posts = [page for page in pages]
    return render_template('base.html', posts=posts)

And this is how you can use load_subs to only load the files inside a specific directory:

@app.route('/<path:sub>/')
def view_page(sub):
        sub_pages = pages.load_subs(sub)
        posts = [page for page in sub_pages]
        return render_template('base.html', posts=posts)

Also, this might help. Unfortunately, I have been unsuccessful in creating a test in tests.py

Collaborator

playpauseandstop commented Feb 2, 2014

@daschwa got you! btw, I decided to provide new filter API which cover your needs.

anschwa commented Feb 2, 2014

That's amazing!

Contributor

fhirschmann commented Feb 2, 2014

This can also be achieved by doing

blog_pages = [p for p in pages if p.path.startswith("blog/")]

anschwa commented Feb 2, 2014

I knew there must have already been a way to do it. Thanks.

@playpauseandstop playpauseandstop modified the milestones: 1.0, 0.6 Feb 9, 2015

Collaborator

playpauseandstop commented Feb 9, 2015

Moved to 1.0 milestone to be completed with new Filter API

@anschwa anschwa closed this Jun 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment