Josh Usre
Josh Usre

Reputation: 683

Python web app setup

I have a python script (2.7) that queries an API and returns information to the user (.csv file). I'd like to make this script available to people that visit my website, which is based on wordpress.

What is the best way to go about this task? People tell me to use django, but I'm not sure where to start:

Do I incorporate my python script into django somehow and have my pages access the DB?

Do I have the script on my server, django in another place, and have all three talking to each other?

Is there a better option?

I just need a "recipe" to help me along my path.

Upvotes: 1

Views: 88

Answers (1)

rdegges
rdegges

Reputation: 33824

For something simple like what you're mentioning above, there's probably no better place for you to dive in than Flask (http://flask.pocoo.org/) -- it's a simple, minimalistic web framework for Python that will help get your stuff up and running quickly.

Here's a full Flask application (an example) that simply returns a CSV file called 'test.csv' to the user who visits the homepage of the site:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def serve_csv():
    return app.send_static_file('test.csv')

if __name__ == '__main__':
    app.run()

This example assumes you've got a project that looks like this:

project
├── app.py
└── static
    └── test.csv

You should probably head over to the Flask website to read a bit more about it: http://flask.pocoo.org/

Upvotes: 1

Related Questions