Web application with python
Question: I have a Python program that takes one input (string) and prints out several
lines as an output. I was hoping to get it online, so that the web page only
has a text-area and a button. Inserting a string and pressing the button
should send the string to python and make the original page print out the
output from Python.

Assuming I have only dealt with Python and a little bit of HTML and have very
limited knowledge about the web, how might I approach this problem?

For some reason, my first instinct was PHP, but Googling "PHP Python
application" didn't really help.

That is, assuming what I want IS a 'web application', right? Not a web server,
web page or something else?

How could I get a really simple version (like in the first paragraph) up and
running, and where to learn more?


Answer: Yes, the term you're looking for is "web application". Specifically, you want
to host a Python web application.

Exactly what this means, can vary. There are two main types of application -
`cgi` and `wsgi` (or stand-alone, which is what most people talk about when
they say "web app").

Almost nobody uses cgi nowadays, you're much more likely to come across a site
using a web application framework, like Django or Flask.

If you're worried about easily making your page accessible to other people, a
good option would be to use something like the free version of Heroku do to
something simple like this. They have a guide available here:

<https://devcenter.heroku.com/articles/getting-started-with-
python#introduction>

If you're more technically inclined and you're aware of the dangers of opening
up your own machine to the world, you could make a simple Flask application
that does this and just run it locally:

    
    
    from flask import Flask, request
    
    app = Flask(__name__)
    
    
    @app.route('/')
    def main():
        return 'You could import render_template at the top, and use that here instead'
    
    @app.route('/do_stuff', methods=['POST'])
    def do_stuff():
        return 'You posted' + request.form.get('your string')
    
    app.run('127.0.0.1', port=5555, debug=True)
    

