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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:56:15+00:00 2026-05-24T00:56:15+00:00

My controllers are getting a bit cluttered in my web2py app, and I would

  • 0

My controllers are getting a bit cluttered in my web2py app, and I would like to move functions to another place.

I was initially thinking of moving them to modules, but I access the db sometimes, and have other parameters set in db.py (me for user id, now for the date, etc.).

Is there a clean way to move these functions to a new file while still having access to the variables I need? I’m not opposed to something like from db import me, now

  • 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-24T00:56:16+00:00Added an answer on May 24, 2026 at 12:56 am

    You controller actions (i.e., the actions that appear in URLs) have to be functions defined in a controller file (i.e., you cannot move them to a module). However, if there are functions in your controller that are not actions, you may move those to a module. Assuming you will call those functions from a model or controller, you can simply pass your db, me, and now objects to those functions as arguments. Another option is to add them to the thread local current object, which can be accessed from modules. To do so:

    In a model:

    from globals import current
    current.app.db = db
    # etc.
    

    In a module:

    from globals import current
    
    def func(*args):
        db=current.app.db
        # etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble getting a rotary encoder to work properly with AVR micro controllers.
Say I have the following file structure: app/ app.py controllers/ __init__.py project.py plugin.py If
I'm having a tad bit of trouble getting the jQuery Form Plugin to work
I'm starting out a Spring MVC 3.0 application and getting controllers and views working
I am having a bit of trouble getting these polymorphic associations to work completely.
I have two controllers which share most of their code (but must be, nonetheless,
Ruby on Rails controllers will automatically convert parameters to an array if they have
I've been refactoring my models and controllers in an effort to remove code duplication,
What's the use of the controllers in SubSonic?
Does anyone have any code examples on how to create controllers that have parameters

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.