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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:22:51+00:00 2026-06-17T22:22:51+00:00

Embarrassed to ask but I am using webapp2 and I am templating out a

  • 0

Embarrassed to ask but I am using webapp2 and I am templating out a solution to make it easier to define routesbased on this google webapp2 route function. But it all depends on being able to define TYPE_NAME at the child level. The idea is the parent sets everything up and the child just needs to implement the _list function. The issue I ran into is TYPE_NAME is None and I need it to be the child.

#main WSGI is extended to have this function 
class WSGIApplication(webapp2.WSGIApplication):
    def route(self, *args, **kwargs):
        def wrapper(func):
            self.router.add(webapp2.Route(handler=func, *args, **kwargs))
            return func

        return wrapper

from main import application
class ParentHandler(RequestHandler):
    TYPE_NAME = None

    @application.route('/', name="list_%s" %TYPE_NAME)
    def list(self):
          return self._list()

class ChildHandler(ParentHandler):
    TYPE_NAME = 'child'

    def _list(self):
         return []

I have tried a couple solutions using “class properties” but they didn’t pan out. Open to other ideas, I basically just need the child class to inherit the decorated properties and execute them.

Edit:

For all of those on the edge of their seats wondering how I fix this,I was not able to get everything I needed out of the decorator so I ended up using a meta. I also added a _URLS parameter to allow for adding additional “routes”. It maps custom function to the route. Really wanted to use a decorator but couldn’t get it to work.

class RequestURLMeta(type):
    def __new__(mcs, name, bases, dct):
        result = super(RequestURLMeta, mcs).__new__(mcs, name, bases, dct)
        urls = getattr(result, '_URLS', {}) or {}
        for k,v in urls.iteritems():
            template = v.pop('template')
            app.route(getattr(result, k), template, **v)

        if getattr(result, 'TYPE_NAME', None):
            app.route(result.list, result.ROOT_PATH, methods=['GET'],name="%s" % result.TYPE_NAME)
        #other ones went here..

    return result

class ParentHandler(RequestHandler):
    __metaclass__ = RequestURLMeta


class ChildHandler(ParentHandler):
    TYPE_NAME = 'child'
    _URLS = { 'custom': '/custom', 'TYPE_NAME': 'custom_test' }
    def _list(self):
        return []
    def custom(self):  pass
  • 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-17T22:22:52+00:00Added an answer on June 17, 2026 at 10:22 pm

    I think to get this to work you are going to need to use a metaclass. It might look something like the following (untested):

    from main import application
    
    class RouteMeta(type):
        def __new__(mcs, name, bases, dct):
            type_name = dct.get("TYPE_NAME")
            if type_name is not None:
                @application.route('/', type_name)
                def list(self):
                    return self._list()
                dct["list"] = list
            return super(RouteMeta, mcs).__new__(mcs, name, bases, dct)
    
    class ParentHandler(RequestHandler):
        __metaclass__ = RouteMeta
    
    class ChildHandler(ParentHandler):
        TYPE_NAME = 'child'
    
        def _list(self):
             return []
    

    Instead of having the list() method an attribute of ParentHandler, it is dynamically created for classes that inherit from ParentHandler and have TYPE_NAME defined.

    If RequestHandler also uses a custom metaclass, have RouteMeta inherit from RequestHandler.__metaclass__ instead of type.

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

Sidebar

Related Questions

I'm embarrassed to even ask this question, but after an exhausting search in google
I'm embarrassed to ask this, but I cannot figure out how to run a
I am almost embarrassed to ask this question, but as a long time C
This is so simple I'm embarrassed to ask, but how do you convert a
I'm trying to figure this simple thing but I'm actually embarrassed to ask such
I'm a little embarrassed to ask this as I ought to know better, but
This is probably trivial - I almost feel embarrassed to ask, but I am
I'm a bit embarrassed to ask about this, but I'm struggling with centering a
I am embarrassed to ask this simple question, but has been in kicking my
This is a dumb question and I feel embarrassed to ask it, but I'm

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.