{"id":4360,"library":"flask-flatpages","title":"Flask-FlatPages","description":"Flask-FlatPages provides an easy way to integrate flat static pages, written in formats like Markdown or reStructuredText, into a Flask web application. It is currently at version 0.9.0, primarily focusing on maintenance releases and preparing for future feature additions in an eventual 1.0 release.","status":"active","version":"0.9.0","language":"python","source_language":"en","source_url":"https://github.com/Flask-FlatPages/Flask-FlatPages","tags":["flask","static pages","markdown","cms","blog"],"install":[{"cmd":"pip install Flask-FlatPages","lang":"bash","label":"Install Flask-FlatPages"}],"dependencies":[{"reason":"Core web framework dependency.","package":"Flask","optional":false},{"reason":"Required for Markdown content rendering, common but can be replaced with custom renderers.","package":"Markdown","optional":true},{"reason":"Optional for code highlighting within Markdown pages.","package":"Pygments","optional":true}],"imports":[{"symbol":"FlatPages","correct":"from flask_flatpages import FlatPages"},{"symbol":"Page","correct":"from flask_flatpages import Page"}],"quickstart":{"code":"import os\nfrom flask import Flask, render_template\nfrom flask_flatpages import FlatPages\n\n# Configuration\nDEBUG = True\nFLATPAGES_AUTO_RELOAD = DEBUG\nFLATPAGES_EXTENSION = '.md'\nFLATPAGES_ROOT = 'pages'\nFLATPAGES_ENCODING = 'utf-8'\n\napp = Flask(__name__)\napp.config.from_object(__name__)\nflatpages = FlatPages(app)\n\n# Routes\n@app.route('/')\ndef index():\n    # All pages are available via flatpages iterable\n    return render_template('index.html', pages=flatpages)\n\n@app.route('/<path:path>/')\ndef page(path):\n    # Get a specific page, or 404\n    page = flatpages.get_or_404(path)\n    return render_template('page.html', page=page)\n\nif __name__ == '__main__':\n    # Create dummy content and templates for runnable quickstart\n    if not os.path.exists(FLATPAGES_ROOT):\n        os.makedirs(FLATPAGES_ROOT)\n    with open(os.path.join(FLATPAGES_ROOT, 'about.md'), 'w') as f:\n        f.write('---\\ntitle: About Us\\ndate: 2024-05-15\\n---\\n\\n# Welcome to our About Page\\n\\nThis is an example flat page managed by Flask-FlatPages.')\n    \n    if not os.path.exists('templates'):\n        os.makedirs('templates')\n    with open('templates/index.html', 'w') as f:\n        f.write('<!doctype html>\\n<html>\\n<head><title>FlatPages Index</title></head>\\n<body>\\n    <h1>FlatPages Example</h1>\\n    <ul>\\n        {% for page in pages %}\\n            <li><a href=\"{{ url_for(\"page\", path=page.path) }}\">{{ page.meta.get(\"title\", page.path) }}</a></li>\\n        {% endfor %}\\n    </ul>\\n</body>\\n</html>')\n    with open('templates/page.html', 'w') as f:\n        f.write('<!doctype html>\\n<html>\\n<head><title>{{ page.meta.get(\"title\", \"Page\") }}</title></head>\\n<body>\\n    <h1>{{ page.meta.get(\"title\", \"\") }}</h1>\\n    {{ page.html|safe }}\\n</body>\\n</html>')\n\n    # Run the Flask app\n    app.run(port=5000, debug=DEBUG)","lang":"python","description":"This quickstart initializes a Flask application with Flask-FlatPages, serving flat markdown pages. It demonstrates how to configure the extension, list all available pages, and retrieve a specific page based on its path. It also includes boilerplate to create dummy files, allowing the example to run out-of-the-box."},"warnings":[{"fix":"Migrate to using `flask.current_app` directly where possible, or ensure an application context is always pushed when `FlatPages.app` is accessed.","message":"Directly accessing the `FlatPages.app` attribute is deprecated. In versions 0.9 and up, it now wraps `flask.current_app`, and attempting to access it outside of an active Flask application context will raise a `RuntimeError`.","severity":"deprecated","affected_versions":"0.8.3+"},{"fix":"Ensure your Python development and deployment environments are running Python 3.8 or newer to use current versions of Flask-FlatPages.","message":"Support for older Python versions has been progressively dropped. Python 2.7 support was removed in v0.8.2. Python 3.7 and earlier are no longer supported as of v0.9.0, requiring Python 3.8+.","severity":"breaking","affected_versions":"0.8.2+, 0.9.0+"},{"fix":"No direct code changes are typically required. Test existing pages with v0.8.0+ to confirm metadata extraction remains correct.","message":"Metadata parsing was improved in v0.8.0 to be more consistent with other 'FlatPage' style libraries and less strict for pages without explicit metadata. While generally an enhancement, review your existing flat page metadata to ensure it's parsed as expected, especially if you relied on previous implicit behaviors.","severity":"gotcha","affected_versions":"0.8.0+"},{"fix":"Always update Flask-FlatPages and its dependencies (e.g., Flask, Markdown) to the latest stable versions. Regularly review your project's dependencies for security alerts.","message":"Multiple releases have included updates to underlying dependencies or dropped support for older Python versions to address security vulnerabilities. Running outdated versions can expose your application to known security risks.","severity":"breaking","affected_versions":"All versions prior to 0.9.0"}],"env_vars":null,"search_vec":"'0.9.0':33 '1.0':48 'addit':44 'applic':27 'blog':55 'cms':54 'current':30 'easi':9 'eventu':47 'featur':43 'flask':2,5,25,50 'flask-flatpag':1,4 'flat':13 'flatpag':3,6 'focus':35 'format':18 'futur':42 'integr':12 'like':19 'mainten':37 'markdown':20,53 'page':15,52 'prepar':40 'primarili':34 'provid':7 'releas':38,49 'restructuredtext':22 'static':14,51 'version':32 'way':10 'web':26 'written':16","created_at":"2026-04-12T08:52:26.892313+00:00","updated_at":"2026-04-16T15:07:00.854207+00:00","problems":[{"fix":"Update your import statement to `from flask_flatpages import FlatPages`.","cause":"The `flask.ext` namespace was deprecated in Flask 0.9. Flask extensions are now imported directly from their package names (e.g., `flask_flatpages` instead of `flask.ext.flatpages`).","error":"ModuleNotFoundError: No module named 'flask.ext.flatpages'"},{"fix":"Ensure that your `page.html` (or equivalent) template file exists inside a `templates` directory at the root of your Flask application. Also, verify that the `render_template` call correctly references this file, e.g., `render_template('page.html', page=page)`.","cause":"This error occurs when Flask's Jinja2 templating engine cannot find the HTML template file specified in your `render_template` call, which is commonly `page.html` or a similar wrapper template used to display the content of a `flask-flatpages` page. The template file is either missing, located in an incorrect directory, or has a typo in its name. By default, Flask looks for templates in a folder named `templates` in your application's root directory.","error":"jinja2.exceptions.TemplateNotFound: page.html"},{"fix":"Ensure that the variable you are calling `.get()` on is the `FlatPages` instance itself and that you are using it to retrieve a `Page` object, for example: `page = pages.get(path)` or `page = pages.get_or_404(path)`. If you are iterating over pages, ensure you are accessing properties like `page.html` or `page.meta` correctly on the individual `Page` objects.","cause":"This error indicates that you are attempting to call a method or access an attribute named 'get' on an object that is not an instance of `FlatPages` or an object that has been incorrectly initialized or overwritten. In `flask-flatpages`, the `FlatPages` instance itself usually doesn't have a `.get()` method; rather, you might be trying to access a page using `pages.get(path)` where `pages` is expected to be an instance of `FlatPages` and `get` is a method on it. The documentation shows `FlatPages.get('foo')` as a way to force loading, but the more common usage is iterating over `pages` and then accessing attributes of individual `Page` objects. Or, if 'get' is called on a `Page` object, `Page` objects do not have a `.get()` method.","error":"AttributeError: 'FlatPages' object has no attribute 'get'"},{"fix":"If you intend to use Jinja2 expressions inside your flatpages, you need a custom HTML renderer that pre-renders the Jinja2 in the flatpage body *before* Markdown processing, or a custom approach that allows for a second pass of Jinja2 rendering. A common workaround is to use a custom `FLATPAGES_HTML_RENDERER` that explicitly calls Jinja2's `render_template_string` on the flatpage's body before or after Markdown conversion.","cause":"By default, when `flask-flatpages` renders a page's content, it often passes the processed HTML directly into a Jinja2 template using `{{ page.html | safe }}`. The `| safe` filter tells Jinja2 to treat the content as safe HTML, preventing it from re-evaluating any Jinja2 expressions present within the flatpage's body. Thus, Jinja2 expressions within the flatpage's Markdown or HTML will be displayed as literal text rather than being processed.","error":"Jinja2 expressions in flatpages (e.g., {{ 1 + 1 }}) are not rendered, showing literally."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.9.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/Flask-FlatPages/Flask-FlatPages","docs":"https://flask-flatpages.readthedocs.io/en/latest/","changelog":null,"pypi":"https://pypi.org/project/flask-flatpages/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-29","next_check":"2026-07-28","install_tag":null}}