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 6217401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:25:14+00:00 2026-05-24T07:25:14+00:00

Flask provides a url_for function to generate URLs to handlers based on the URL

  • 0

Flask provides a url_for function to generate URLs to handlers based on the URL pattern. But this would imply that the handler functions must have unique names across the entire application. Is that correct?

Example

Module A has a handler index:

@app.route('/')
def index(): pass

And Module B has another handler index:

@app.route('/anotherindex')
def index(): pass

How to distinguish the handlers called index when building URLs?

url_for('index')
  • 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-05-24T07:25:15+00:00Added an answer on May 24, 2026 at 7:25 am

    I don’t know how you could do with all the views routed by the same module.

    What I usually do is separate my views in different modules (like you did with module A and B), and register them as blueprints, after that, when using the url_for() function, you can prefix the view name with your blueprint name and then avoid conflicts and potential problems.

    Here is an example:

    main_views.py:

    from flask import Blueprint
    main = Blueprint('main', __name__)
    
    @main.route('/')
    def index():
        pass
    

    admin_views.py:

    from flask import Blueprint
    admin = Blueprint('admin', __name__)
    
    @admin.route('/admin')
    def index():
        pass
    

    application.py:

    from flask import Flask
    from main_views import main
    from admin_views import admin
    
    app = Flask('my_application')
    app.register_blueprint(main)
    app.register_blueprint(admin)
    

    Now, to access the 2 index views and still distinguish one from the other, just use url_for('main.index') or url_for('admin.index')

    EDIT:

    Just one more useful details about routing using blueprints, when registering the blueprint, you can pass a url_prefix argument, that will apply to every view within this blueprint.

    For example, given the following code:

    admin_views.py

    from flask import Blueprint
    admin = Blueprint('admin', __name__)
    
    @admin.route('/')
    def index():
        pass
    
    @admin.route('/logout')
    def logout():
        pass
    

    application.py:

    from flask import Flask
    from admin_views import admin
    
    app = Flask('my_application')
    app.register_blueprint(admin, url_prefix='/admin')
    

    The 2 views would be available at the URL /admin/ and /admin/logout

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I didn't think this was possible, but http://www.snapabug.com provides a service that uses screen
I have this swf (flash) file that provides the json that needs to be
I know there are already articles that covered this, but I'm having an issue
Flash receives the XML, but the values are wrong. How do I fix this?
I have an html page with a flash object that provides video chat using
Is there any method equivalent to Rails / Flask ’s url_for on Express.js ?
Hi I know this question have been asked before but the answers there isn't
I am creating Flash Media Servers using an AMI that Adobe provides. I need
This is a pretty generic question, but I come from a few years with
I know other questions have been asked on this but none so far 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.