Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8919127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:56:16+00:00 2026-06-15T05:56:16+00:00

I want breadcrumbs for navigating my Flask app. An option could be to use

  • 0

I want breadcrumbs for navigating my Flask app. An option could be to use a general Python module like bread.py:

The bread object accepts a url string and grants access to the url
crumbs (parts) or url links (list of hrefs to each crumb) .

bread.py generates the breadcrumb from the url path, but I want the elements of the breadcrumb to be the title and link of the previously visited pages.

In Flask, maybe this can be done using a decorator or by extending the @route decorator.

Is there a way to have each call of a route() add the title and link of the page (defined in the function/class decorated with @route) to the breadcrumb? Are there other ways to do it? Any examples of breadcrumbs implemented for Flask?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:56:18+00:00Added an answer on June 15, 2026 at 5:56 am

    So you’re after “path/history” breadcrumbs, rather than “location” breadcrumbs to use the terminology from the wikipedia article?

    If you want to have access to the user’s history of visited links, then you’re going to have to save them in a session. I’ve had a go at creating a decorator to do this.

    breadcrumb.py:

    import functools
    import collections
    
    import flask
    
    BreadCrumb = collections.namedtuple('BreadCrumb', ['path', 'title'])
    
    def breadcrumb(view_title):
        def decorator(f):
            @functools.wraps(f)
            def decorated_function(*args, **kwargs):
                # Put title into flask.g so views have access and
                # don't need to repeat it
                flask.g.title = view_title
                # Also put previous breadcrumbs there, ready for view to use
                session_crumbs = flask.session.setdefault('crumbs', [])
                flask.g.breadcrumbs = []
                for path, title in session_crumbs:
                    flask.g.breadcrumbs.append(BreadCrumb(path, title))
    
                # Call the view
                rv = f(*args, **kwargs)
    
                # Now add the request path and title for that view
                # to the list of crumbs we store in the session.
                flask.session.modified = True
                session_crumbs.append((flask.request.path, view_title))
                # Only keep most recent crumbs (number should be configurable)
                if len(session_crumbs) > 3:
                    session_crumbs.pop(0)
    
                return rv
            return decorated_function
        return decorator
    

    And here’s a test application that demonstrates it. Note that I’ve just used Flask’s built-in client side session, you’d probably want to use a more secure server-side session in production, such as Flask-KVsession.

    #!/usr/bin/env python
    import flask
    from breadcrumb import breadcrumb
    
    app = flask.Flask(__name__)
    
    @app.route('/')
    @breadcrumb('The index page')
    def index():
        return flask.render_template('page.html')
    
    @app.route('/a')
    @breadcrumb('Aardvark')
    def pagea():
        return flask.render_template('page.html')
    
    @app.route('/b')
    @breadcrumb('Banana')
    def pageb():
        return flask.render_template('page.html')
    
    @app.route('/c')
    @breadcrumb('Chimp')
    def pagec():
        return flask.render_template('page.html')
    
    @app.route('/d')
    @breadcrumb('Donkey')
    def paged():
        return flask.render_template('page.html')
    
    if __name__ == '__main__':
        app.secret_key = '83cf5ca3-b1ee-41bb-b7a8-7a56c906b05f'
        app.debug = True
        app.run()
    

    And here’s the contents of templates/page.html:

    <!DOCTYPE html>
    <html>
        <head><title>{{ g.title }}</title></head>
        <body>
            <h1>{{ g.title }}</h1>
            <p>Breadcrumbs:
            {% for crumb in g.breadcrumbs %}
                <a href="{{ crumb.path }}">{{ crumb.title }}</a>
                {% if not loop.last %}&raquo;{% endif %}
            {% endfor %}
            </p>
            <p>What next?</p>
            <ul>
                <li><a href="/a">Aardvark</a>?</li>
                <li><a href="/b">Banana</a>?</li>
                <li><a href="/c">Chimp</a>?</li>
                <li><a href="/d">Donkey</a>?</li>
            </ul>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

want to know why String behaves like value type while using ==. String s1
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
I got breadcrumbs and its build up like this. <div> <p> <a> so i
For example, let's say I want to modify the breadcrumbs block of the admin/change_list.html
I have done stuff like this before, but I want to figure out the
I want to implement some tooltip for breadcrumbs is there a way to do
I make use of Zend_Navigation and its menu helper and breadcrumbs helper together with
i have a small problem... i want to bind my app to adminsite. my
I have a <div id=bread></div> and I am trying to display breadcrumbs where one
I want my ASP.NET site to have simple menu string aka Breadcrumbs. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.