Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

This is my first python application (I have some experience in Java/groovy-grails), and therefore I am not confident of the application structure I should be following.

My application has two functionalities. One is providing a restful API, and the other is providing few web pages, for signup, contact form, stats, etc.

Currently, all the actions for the 'frontend' of the service, are within a .py called 'my_app.py'. This contains a number of lines as

#Get the database name from the config file
app.config['MONGODOCS'] = data.config[0]['MONGODOCS']

and at the end:

if __name__ == '__main__':
    app.debug = True
    app.run(host='0.0.0.0')

My functions look like this:

# This is a webpage response
@app.route('/process/')
def process():
    return render_template('process.html')

#This is an API response
@app.route('/my_app/api/v1.0/question/<string:q_id>/reject', methods = ['POST'])
def question_reject(q_id):
#do something here

As the functions and config get more, I start to think that they should be separated in different, specialized places, for example one place/ .py file for loading all the configuration and setting the options, one for handling routing and processing for the webpages, and one for the REST api calls. Then my current my_app.py should simply put these three pieces together.

Assuming the above highlighted code is all the contents of my_app.py, whats the pythonic way of breaking down this file in smaller components ?

Also, is this something I should do, based on python design standards?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.