Hi all, am wondering if I'm doing this right.
I want to split a huge py file into ten .py files ( or controllers, if you will). The reason being it's neat, and doesn't contain thousands of code lines in one single file.
Every .py file will have its own request handler.
Each .py file will serve a certain function.
(the questions come after the Code section)
Code:
# *****app.yaml*****
handlers:
url: /part1
script: controllers/part1.py
url: /part2
script: controllers/part2.py
# this goes on until part10.py
# ***** part1.py (this is the entry point of the application)*****
# all required imports ( about 20 imports, some from app engine, some from external libs )
class Part1(webapp.RequestHandler):
# a lot of code here
# Models are accessed, data retrieved and worked upon. Results of the work are
# sent directly to the template_values variable
# point to template
path = os.path.join(os.path.dirname(__file__), 'templates/part1.html')
template_values = { 'variable ':variable }
# render template
self.response.out.write(template.render(path, template_values))
# the standard WSGI calls
application = webapp.WSGIApplication([('/part1', Part1)],debug=True)
def main(): run_wsgi_app(application)
if __name__ == "__main__": main()
Additional notes: for part2.py until part10.py, it follows the exact same format as part1.py.
So far it's been working for me on both dev and production server.
My worries:
1. Am I taxing the app engine server bcos the imports in each .py file are repetitive?
2. Is it okay to have a request handler for each .py file? Am I consuming too much resource?
The big question is, can I keep doing this as my application grows ( as I add more code/functionality) ? Is this the way to expand all the way up to N numbers of .py files? What are the drawbacks?
Hope you guys can give some insights on this.
Been thinking about this for weeks.