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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:34:58+00:00 2026-06-05T15:34:58+00:00

I have been studying python for quite sometime now and very recently I decided

  • 0

I have been studying python for quite sometime now and very recently I decided to get into learning web development side of things. I have experience with PHP and PHP frameworks, along with ruby, where:

  • Routes are defined in a (single) file and then in that file, each route is assigned to a model (py file) which will uniquely handle incoming requests matching that route.

How can I achieve this with flask AND webapp2?

I read the documentation and tutorial in full but it got me very confused. I just want A file where all routes and how should they be handled are set, and then each route request to be handled by its own model (python file).

All the examples lead to single file apps.

Thank you VERY MUCH, really. Please teach, kindly, in a simple way.

  • 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-05T15:35:01+00:00Added an answer on June 5, 2026 at 3:35 pm

    Webapp2 actually provides this out of the box – the WSGIApplication class instances have an instance of Router provided in their router attribute that can be used for centralized URL maping as shown in the documentation.

    Flask doesn’t, but this is actually documented in its most basic form in Patterns for Flask: Lazy Loading. Using the LazyView class it defines you can build out a system to provide central URL maps – either to a pre-defined symbol in each of your modules or to particular functions or class instances in your modules.

    I actually recently published a package (HipPocket) that provides wrappers to simplify getting started with this pattern. It provides two classes for this purpose LateLoader and Mapper. Using HipPocket your central route configuration file could look something like this (this assumes a package layout similar to what is discussed here):

    app.py

    from flask import Flask
    
    app = Flask("yourapp")
    # ... snip ...
    

    urls.py

    from .app import app
    from hip_pocket import Mapper
    
    mapper = Mapper(app)
    
    mapper.add_url_rule("/", "index.index")
    mapper.add_url_rule("/test", "index.test_endpoint", methods=["POST"])
    
    mapper.add_url_rule("/say-hello/<name>",
                            "say_hello.greeter",
                            methods=["GET", "POST"])
    

    index.py

    def index():
        return "Hello from yourapp.index.index!"
    
    def test_endpoint():
        return "Got a post request at yourapp.index.test_endpoint"
    

    say_hello.py

    def say_hello(name=None):
        name = name if name is not None else "World"
        return "Greetings {name}!".format(name=name)
    

    run_app.py

    from yourapp.app import app
    from yourapp.urls import mapper
    # We need to import the mapper to cause the URLs to be mapped.
    
    if __name__ == "__main__":
        app.run()
    

    Pull requests and issue reports are welcome!

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

Sidebar

Related Questions

I have been studying unicode and its Python implementation now for two days, and
I've been studying Python 3 recently and I have come across a conundrum: I
I've recently begun my journey of learning CSS, and have been studying Gmail's design,
I am new to Python and have been studying its fundementals for 3 months
I've recently been studying TDD, attended a conference and have dabbled in few tests
I'm a Maven newbie, have been studying Maven for a week now, have 5
I've recently been studying Qt, and have the following questions: What is the difference
I am continually studying up on languages I have been using and learning, as
i have been recently studying php and mysql and also is currently developing a
I have been studying SOAP and WSDL in preparation for implementing a web service.

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.