Question on how to modularize handlers

63 views
Skip to first unread message

Shan Sikdar

unread,
Nov 9, 2012, 10:18:35 AM11/9/12
to google-a...@googlegroups.com
Hi basic question,

Basically I'm having trouble modularizing handlers in GAE.

Specifically in my application I have a download button that calls a Test handler so far I have:
 <script>    
 $('#download').button().click(function(){
            $('<iframe id="dlBox" name="dlBox" hieght=0px width=0px src="/test">').appendTo('body');
             
        });
</script>

And then at the bottom of the code I have :

class Test(webapp2.RequestHandler):
    def get(self):
        logging.info("Entered Handler")
        self.response.headers['Content-Type'] = 'text/csv'
        self.response.headers['Content-Disposition'] = "attachment; filename=fname.csv"
        self.response.out.write(','.join(['a', 'cool', 'test']))        

application = webapp2.WSGIApplication([('/', MainHandler),
                                        ('/query', QueryHandler),
                                      ('/test', Test) ],
                                        debug=True)      
And this works but I want to be able to make the Test class into its own .py file.

So I made a folder called handlers saved the class as test.py and then changed my app.yaml to include:
- url: /test
  script: handlers/test.py

However when I try clicking the download button it gives the error : ImportError('Could not find module %s' % fullname)
ImportError: Could not find module handlers.test

I have also tried changing the app.yaml to:
- url: /handlers
  static_dir: handlers

and changing the source in the javascript code to src="/handlers/test.py" but in this case there's no error but also it doesn't enter the handler at all it simply just says "GET /handlers/test.py HTTP/1.1" 200 -

What am I missing?

Thanks!

       

Kyle Finley

unread,
Nov 9, 2012, 6:52:35 PM11/9/12
to google-a...@googlegroups.com
Shan, if you are using the python27 runtime it should be:

# app.yaml

runtime: python27

Anand Mistry

unread,
Nov 11, 2012, 12:02:21 AM11/11/12
to google-a...@googlegroups.com
Two things:
1. You need an __init__.py file in the handlers directory
2. Your script line should read 'handlers.test.application'
Reply all
Reply to author
Forward
0 new messages